using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;

using GonzalesCore.CoreElements;

using Kypris2.Utils;
using Kypris2.CoreElements;
using Kypris2.CoreManagers;

using Jamila2.CoreElements;
using Jamila2.Database;
using Jamila2.Tools;

namespace GonzalesCore.CoreManagers
{    
    public class ClaimManager : KyprisManagerBase, IManager, IDisposable
    {
        private GonzalesDataStructure DataStructrure = new GonzalesDataStructure();
        private PersonalSessionAccount CurrentModuleSession = null;
        private LogManager CurrentLogManager = null;

        public ClaimManager(PersonalSessionAccount PrivateConfig)
            : base(PrivateConfig)
        {
            this.CurrentModuleSession = PrivateConfig;
            this.CurrentLogManager = new LogManager(PrivateConfig);            
        }

        #region Enum

        #region ApprovingStructure
        public static int GetApprovingRouteInCode(ApprovingRoute AppRoute)
        {
            int result = 0;

            switch (AppRoute) {
                case ApprovingRoute.Normal:
                    result = 0;
                    break;

                case ApprovingRoute.MultiLevel:
                    result = 1;
                    break;

                case ApprovingRoute.Exception:
                    result = 2;
                    break;
            }

            return result;
        }

        public static ApprovingRoute GetApprovingRoute(int AppRoute)
        {
            ApprovingRoute result = 0;

            switch (AppRoute)
            {
                case 0:
                    result = ApprovingRoute.Normal;
                    break;

                case 1:
                    result = ApprovingRoute.MultiLevel;
                    break;

                case 2:
                    result = ApprovingRoute.Exception;
                    break;
            }

            return result;
        }

        public static string GetApprovingRoute(ApprovingRoute AppRoute)
        {
            string result = "Normal";

            switch (AppRoute)
            {
                case ApprovingRoute.Normal:
                    result = "Normal";
                    break;

                case ApprovingRoute.MultiLevel:
                    result = "MultiLevel";
                    break;

                case ApprovingRoute.Exception:
                    result = "Exception";
                    break;
            }

            return result;
        }
        #endregion        

        #region Claim Status

        public static int GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus status)
        {
            int result = 0;

            switch (status)
            {
                case GonzalesClaimHeader.TypeOfClaimStatus.New:
                    result = 0;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Draft:
                    result = 1;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Submitted:
                    result = 2;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Escalated:
                    result = 3;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Approved:
                    result = 4;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Authorized:
                    result = 5;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.PendingForFinanceVerification:
                    result = 6;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.SubmittedForPayment:
                    result = 7;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.PendingForAuthorize:
                    result = 8;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Verified:
                    result = 97;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Processed:
                    result = 98;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.FinanceApproval:
                    result = 99;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Paid:
                    result = 100;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.RejectedByApprover:
                    result = 101;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.RejectedByAuthorizer:
                    result = 102;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinance:
                    result = 103;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApprover:
                    result = 104;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApproverToFA:
                    result = 106;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.OnHold:
                    result = 105;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Cancelled:
                    result = 200;
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.ProcessedUpdated:
                    result = 201;
                    break;



            }

            return result;
        }

        public static string GetClaimStatusInString(GonzalesClaimHeader.TypeOfClaimStatus status)
        {
            string result = "";

            switch (status)
            {
                case GonzalesClaimHeader.TypeOfClaimStatus.New:
                    result = "New";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Cancelled:
                    result = "Cancelled";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Draft:
                    result = "Draft";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Escalated:
                    //result = "Escalated";
                    result = "Pending for Higher Approver";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Approved:
                    result = "Approved";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Authorized:
                    result = "Authorized";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.PendingForFinanceVerification:
                    result = "Pending for Finance Admin";
                    //result = "Pending for Approval";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.SubmittedForPayment:
                    result = "Submitted for Payment";
                    //result = "Approved Claim";
                    break;
                    
                case GonzalesClaimHeader.TypeOfClaimStatus.PendingForAuthorize:
                    result = "Pending for Authorizer";
                    //result = "Pending for Approval";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Paid:
                    result = "Paid";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Verified:
                    //result = "Verified";
                    result = "Pending for Finance Verifier";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Processed:
                    result = "Processed";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.FinanceApproval:
                    result = "Pending for Finance Verifier";
                    //result = "Pending for Approval";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.RejectedByApprover:
                    result = "Rejected By Approver";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.RejectedByAuthorizer:
                    result = "Rejected By Authorizer";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinance:
                    result = "Rejected By Finance Admin";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApprover:
                    result = "Rejected By Finance Verifier";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApproverToFA:
                    result = "Rejected By Finance Verifier";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.OnHold:
                    result = "On Hold By Finance Admin";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.Submitted:
                    //result = "Submitted";
                    result = "Pending for Approver";
                    break;

                case GonzalesClaimHeader.TypeOfClaimStatus.ProcessedUpdated:
                    result = "Processed (Updated)";
                    break;
            }

            return result;
        }

        public static GonzalesClaimHeader.TypeOfClaimStatus GetClaimStatusFromCode(string code)
        {
            GonzalesClaimHeader.TypeOfClaimStatus result = GonzalesClaimHeader.TypeOfClaimStatus.Null;

            switch (code)
            {
                case "0":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.New;
                    break;

                case "1":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.Draft;
                    break;

                case "2":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.Submitted;
                    break;

                case "3":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.Escalated;
                    break;

                case "4":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.Approved;
                    break;

                case "5":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.Authorized;
                    break;

                case "6":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.PendingForFinanceVerification;
                    break;

                case "7":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.SubmittedForPayment;
                    break;

                case "8":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.PendingForAuthorize;
                    break;


                case "97":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.Verified;
                    break;

                case "98":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.Processed;
                    break;

                case "99":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.FinanceApproval;
                    break;

                case "100":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.Paid;
                    break;

                case "101":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.RejectedByApprover;
                    break;

                case "102":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.RejectedByAuthorizer;
                    break;

                case "103":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinance;
                    break;

                case "104":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApprover;
                    break;

                case "106":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApproverToFA;
                    break;

                case "105":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.OnHold;
                    break;

                case "200":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.Cancelled;
                    break;

                case "201":
                    result = GonzalesClaimHeader.TypeOfClaimStatus.ProcessedUpdated;
                    break;


            }

            return result;
        }


        #endregion 

        #region Claim Detail Type
        public static int GetClaimDetailTypeInCode(TypeOfClaimDetail ClaimDetailType)
        {
            int result = 0;

            switch (ClaimDetailType)
            {
                case TypeOfClaimDetail.Cash:
                    result = 0;
                    break;

                case TypeOfClaimDetail.CreditCard:
                    result = 1;
                    break;

            }

            return result;
        }

        public static TypeOfClaimDetail GetClaimDetailTypeFromCode(int ClaimDetailType)
        {
            TypeOfClaimDetail result = TypeOfClaimDetail.Cash;

            switch (ClaimDetailType)
            {
                case 0:
                    result = TypeOfClaimDetail.Cash;
                    break;

                case 1:
                    result = TypeOfClaimDetail.CreditCard;
                    break;

            }

            return result;
        }

        
        #endregion

        #region Claim Detail Limit Duration
        public static int GetClaimTypeLimitDurationInCode(TypeOfClaimLimitDuration ClaimLimitDurationType)
        {
            int result = 0;

            switch (ClaimLimitDurationType)
            {
                case TypeOfClaimLimitDuration.Daily:
                    result = 0;
                    break;

                case TypeOfClaimLimitDuration.Weekly:
                    result = 1;
                    break;

                case TypeOfClaimLimitDuration.Monthly:
                    result = 2;
                    break;

                case TypeOfClaimLimitDuration.CalendarYearly:
                    result = 3;
                    break;

                case TypeOfClaimLimitDuration.FiscalYearly:
                    result = 4;
                    break;

                case TypeOfClaimLimitDuration.PerEvent:
                    result = 5;
                    break;

            }

            return result;
        }

        public static TypeOfClaimLimitDuration GetClaimTypeLimitDurationFromCode(int ClaimLimitDurationType)
        {
            TypeOfClaimLimitDuration result = TypeOfClaimLimitDuration.NoLimit;

            switch (ClaimLimitDurationType)
            {
                case 0:
                    result = TypeOfClaimLimitDuration.Daily;
                    break;

                case 1:
                    result = TypeOfClaimLimitDuration.Weekly;
                    break;

                case 2:
                    result = TypeOfClaimLimitDuration.Monthly;
                    break;

                case 3:
                    result = TypeOfClaimLimitDuration.CalendarYearly;
                    break;

                case 4:
                    result = TypeOfClaimLimitDuration.FiscalYearly;
                    break;

                case 5:
                    result = TypeOfClaimLimitDuration.PerEvent;
                    break;

            }

            return result;
        }

        public static string GetClaimTypeLimitDurationInString(TypeOfClaimLimitDuration ClaimLimitDurationType)
        {
            string result = "No Limit";

            switch (ClaimLimitDurationType)
            {
                case TypeOfClaimLimitDuration.Daily:
                    result = "Daily";
                    break;

                case TypeOfClaimLimitDuration.Weekly:
                    result = "Weekly";
                    break;

                case TypeOfClaimLimitDuration.Monthly:
                    result = "Monthly";
                    break;

                case TypeOfClaimLimitDuration.CalendarYearly:
                    result = "Yearly (Calendar)";
                    break;

                case TypeOfClaimLimitDuration.FiscalYearly:
                    result = "Yearly (Fiscal)";
                    break;

                case TypeOfClaimLimitDuration.PerEvent:
                    result = "Per Event";
                    break;

            }

            return result;
        }



        #endregion

        #region Claim Category

        public static int GetClaimCategoryInCode(CategoryOfClaim category)
        {
            int result = 0;

            switch (category)
            {
                case CategoryOfClaim.General:
                    result = 0;
                    break;

                case CategoryOfClaim.Entertainment:
                    result = 1;
                    break;
            }

            return result;
        }

        public static string GetClaimCategoryInString(CategoryOfClaim category)
        {
            string result = "";

            switch (category)
            {
                case CategoryOfClaim.General:
                    result = "General";
                    break;

                case CategoryOfClaim.Entertainment:
                    result = "Entertainment";
                    break;
            }

            return result;
        }

        public static CategoryOfClaim GetClaimCategoryFromCode(string code)
        {
            CategoryOfClaim result = CategoryOfClaim.General;

            switch (code)
            {
                case "0":
                    result = CategoryOfClaim.General;
                    break;

                case "1":
                    result = CategoryOfClaim.Entertainment;
                    break;
            }

            return result;
        }


        #endregion 

        #endregion

        #region Display

        #region GetClaimByID
        public GonzalesClaimHeader GetClaimByInternalID(string ClaimInternalID)
        {
            GonzalesClaimHeader ResultClaimHeader = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, ClaimInternalID));

            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {
                if (ResultTable.Rows.Count == 1)
                {
                    ResultClaimHeader = this.LoadClaimHeader(ResultTable.Rows[0]);
                }
            }
            else
            {
                // log error
            }

            return ResultClaimHeader;
        }
        #endregion

        #region GetClaimByParentID
        public GonzalesClaimHeader GetClaimByParentID(string ParentID)
        {
            GonzalesClaimHeader ResultClaimHeader = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Parent.ActualFieldName, ParentID));

            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {
                if (ResultTable.Rows.Count == 1)
                {
                    ResultClaimHeader = this.LoadClaimHeader(ResultTable.Rows[0]);
                }
            }
            else
            {
                // log error
            }

            return ResultClaimHeader;
        }
        #endregion

        #region GetSubmittedClaimByApprover
        public ClaimHeaders GetClaimsByApprover(string ApproverInternalID)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParametersGroup KeyParametersGroup = new DatabaseParametersGroup();

            // 1st Group
            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName, ApproverInternalID));
            KeyParametersGroup.Add(KeyParameters);

            // 2nd Group
            KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.Submitted).ToString(), DBDataType.String, DBLinkage.OR));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.Escalated).ToString(), DBDataType.String, DBLinkage.OR));
            KeyParametersGroup.Add(KeyParameters);

            DataTable ResultTable = this.QueryClaimHeader(KeyParametersGroup);


            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);
            }
            else
            {
                this.CurrentLogManager.LogError("[ClaimManager.GetClaimsByApprover] : " + this.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultClaimHeaders;
        }
        #endregion

        #region GetApprovedClaimByAuthorizer
        public ClaimHeaders GetApprovedClaimByAuthorizer(string AuthorizerInternalID)
        {
            ClaimHeaders ResultClaimHeaders = null;


            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextAuthorizer.ActualFieldName, AuthorizerInternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.PendingForAuthorize).ToString()));
            
            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);
            }
            else
            {
                this.CurrentLogManager.LogError("[ClaimManager.GetApprovedClaimByAuthorizer] : " + this.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultClaimHeaders;
        }
        #endregion

        #region GetAuthorizedClaimsByFinanceAdmin
        public ClaimHeaders GetAuthorizedClaimsByFinanceAdmin(string FinanceAdminID)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimsByFinanceAdmin.Param_FinanceAdminID.ActualFieldName, FinanceAdminID));

            if (this.TryConnection())
            {
                this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetClaimsByFinanceAdmin.ActualTableName, KeyParameters);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);
                }
                else
                {
                    this.ErrMsg = "[ClaimManager.GetAuthorizedClaimByFinanceAdmin] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultClaimHeaders;
        }
        #endregion

        #region GetClaimsByFinanceApprover
        public ClaimHeaders GetClaimsByFinanceApprover(string FinanceApproverID)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimsByFinanceApprover.Param_FinanceApproverID.ActualFieldName, FinanceApproverID));

            if (this.TryConnection())
            {
                this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetClaimsByFinanceApprover.ActualTableName, KeyParameters);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);
                }
                else
                {
                    this.ErrMsg = "[ClaimManager.GetClaimsByFinanceAdmin] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultClaimHeaders;
        }
        #endregion

        #region GetHistoryClaimsByFinance
        public ClaimHeaders GetHistoryClaimsByFinance(string FinanceInternalID, GonzalesClaimHeader.TypeOfClaimStatus ClaimStatus)
        {
            ClaimHeaders ResultClaimHeaders = null;


            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, FinanceInternalID));
            if (ClaimStatus != GonzalesClaimHeader.TypeOfClaimStatus.Null)
            {
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(ClaimStatus).ToString()));
            }

            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);
            }
            else
            {
                this.CurrentLogManager.LogError("[ClaimManager.GetClaimsByApprover] : " + this.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultClaimHeaders;
        }
        #endregion

        #region GetClaimItemsByClaimHeader
        public ClaimItems GetClaimItemsByClaimHeader(string ClaimInternalID)
        {
            ClaimItems ResultClaimItems = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ClaimID.ActualFieldName, ClaimInternalID));

            DataTable ResultTable = this.QueryClaimItems(KeyParameters);

            try
            {

                if (ResultTable != null)
                {
                    ResultClaimItems = new ClaimItems();

                    foreach (DataRow ResultRow in ResultTable.Rows)
                    {
                        GonzalesClaimItem CurClaimItem = new GonzalesClaimItem(ResultRow[this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName].ToString());
                        //CurClaimItem.IsPersonnal = (ResultRow[this.DataStructrure.Tables.ClaimDetail.IsPersonal.ActualFieldName].ToString().CompareTo("1") == 0);
                        CurClaimItem.ParentID = ResultRow[this.DataStructrure.Tables.ClaimDetail.Parents.ActualFieldName].ToString();
                        CurClaimItem.ParentIDInFI = ResultRow[this.DataStructrure.Tables.ClaimDetail.ParentsInFI.ActualFieldName].ToString();

                        CurClaimItem.Order = Convert.ToInt32(ResultRow[this.DataStructrure.Tables.ClaimDetail.Order.ActualFieldName].ToString());
                        CurClaimItem.ClaimType = new ClaimType(ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimType.ActualFieldName].ToString(), ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimType.ActualFieldName].ToString());
                        CurClaimItem.ClaimDetailType = ClaimManager.GetClaimDetailTypeFromCode(Convert.ToInt32(ResultRow[this.DataStructrure.Tables.ClaimDetail.DetailType.ActualFieldName].ToString()));
                        CurClaimItem.ClaimDate = (ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimDate.ActualFieldName].ToString().Length > 0) ? DateTime.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimDate.ActualFieldName].ToString()) : DateTime.MinValue;
                        CurClaimItem.DateEnd = (ResultRow[this.DataStructrure.Tables.ClaimDetail.DateEnd.ActualFieldName].ToString().Length > 0) ? DateTime.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.DateEnd.ActualFieldName].ToString()) : DateTime.MinValue;
                        CurClaimItem.Description = ResultRow[this.DataStructrure.Tables.ClaimDetail.Description.ActualFieldName].ToString();
                        CurClaimItem.Country = new Country(
                            ResultRow[this.DataStructrure.Tables.ClaimDetail.CountryCode.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.Tables.ClaimDetail.CountryCode.ActualFieldName].ToString());
                        CurClaimItem.City = ResultRow[this.DataStructrure.Tables.ClaimDetail.City.ActualFieldName].ToString();

                        if (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName].ToString().Length > 0)
                        {
                            CurClaimItem.ClaimedAmountCurrency = new Currency(
                                ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName].ToString(),
                                ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName].ToString());
                        }

                        CurClaimItem.ClaimedAmount = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimed.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimed.ActualFieldName].ToString()) : 0;

                        if (ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName].ToString().Length > 0)
                        {
                            CurClaimItem.ExchangeCurrency = new Currency(
                                ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName].ToString(),
                                ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName].ToString());
                        }

                        CurClaimItem.ExchangeRate = (ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRateFigure.ActualFieldName].ToString().Length > 0) ? float.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRateFigure.ActualFieldName].ToString()) : 0;

                        if (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName].ToString().Length > 0)
                        {
                            CurClaimItem.AmountOutCurrency = new Currency(
                                    ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName].ToString(),
                                    ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName].ToString());
                        }

                        CurClaimItem.AmountOut = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOut.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOut.ActualFieldName].ToString()) : 0;
                        CurClaimItem.AmountFinal = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountFinal.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountFinal.ActualFieldName].ToString()) : 0;
                        CurClaimItem.Tax = (ResultRow[this.DataStructrure.Tables.ClaimDetail.Tax.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.Tax.ActualFieldName].ToString()) : 0;
                        CurClaimItem.Remarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.Remarks.ActualFieldName].ToString();
                        CurClaimItem.ApproverRemarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.ApproverRemarks.ActualFieldName].ToString();
                        CurClaimItem.ApproverState = (ResultRow[this.DataStructrure.Tables.ClaimDetail.ApproverState.ActualFieldName].ToString().CompareTo("1") == 0);
                        CurClaimItem.AuthorizerRemarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.AuthorizerRemarks.ActualFieldName].ToString();
                        CurClaimItem.AuthorizerState = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AuthorizerState.ActualFieldName].ToString().CompareTo("1") == 0);
                        CurClaimItem.FinanceRemarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.FIRemarks.ActualFieldName].ToString();
                        CurClaimItem.FinanceState = (ResultRow[this.DataStructrure.Tables.ClaimDetail.FinanceState.ActualFieldName].ToString().CompareTo("1") == 0);
                        CurClaimItem.HavingPopOut = (ResultRow[this.DataStructrure.Tables.ClaimDetail.OtherReff.ActualFieldName].ToString().CompareTo("1") == 0);
                        CurClaimItem.HavingReceipts = (ResultRow[this.DataStructrure.Tables.ClaimDetail.IsReceipts.ActualFieldName].ToString().CompareTo("1") == 0);
                        CurClaimItem.ProjectID = ResultRow[this.DataStructrure.Tables.ClaimDetail.ProjectID.ActualFieldName].ToString();
                        CurClaimItem.ChargeToProfitCenter = ResultRow[this.DataStructrure.Tables.ClaimDetail.ChargeToProfitCenter.ActualFieldName].ToString();
                        CurClaimItem.ChargeToEmployeeiD = ResultRow[this.DataStructrure.Tables.ClaimDetail.ChargeToEmployeeID.ActualFieldName].ToString();


                        // finalize, add into the collection
                        ResultClaimItems.Add(CurClaimItem);
                    }
                }
            }
            catch (Exception ex)
            {
                this.ErrMsg = ex.Message;                
            }

            return ResultClaimItems;
        }
        #endregion

        #region GetClaimItemsByClaimHeaderInLang
        public ClaimItems GetClaimItemsByClaimHeaderInLang(string ClaimInternalID, Language SpecificLanguage)
        {
            ClaimItems ResultClaimItems = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimDetailInLang.Param_ClaimID.ActualFieldName, ClaimInternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimDetailInLang.Param_Language.ActualFieldName, SpecificLanguage.InternalID));

            this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetClaimDetailInLang.ActualTableName, KeyParameters);

            DataTable ResultTable = null;

            if (this.TryConnection()) {

                ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable == null)
                {
                    this.CurrentLogManager.LogError("[ClaimManager.GetClaimItemsByClaimHeaderInLang] : " + this.CurDBEngine.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }

            // start to load if nothing wrong
            if (ResultTable != null)
            {
                ResultClaimItems = new ClaimItems();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    GonzalesClaimItem CurClaimItem = new GonzalesClaimItem(ResultRow[this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName].ToString());
                    //CurClaimItem.IsPersonnal = (ResultRow[this.DataStructrure.Tables.ClaimDetail.IsPersonal.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.ParentID = ResultRow[this.DataStructrure.Tables.ClaimDetail.Parents.ActualFieldName].ToString();
                    CurClaimItem.ParentIDInFI = ResultRow[this.DataStructrure.Tables.ClaimDetail.ParentsInFI.ActualFieldName].ToString();

                    CurClaimItem.Order = Convert.ToInt32(ResultRow[this.DataStructrure.Tables.ClaimDetail.Order.ActualFieldName].ToString());
                    CurClaimItem.ClaimType = new ClaimType(
                        ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimType.ActualFieldName].ToString(), 
                        ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLang.ClaimTypeDescInLang.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLang.GLCode.ActualFieldName].ToString());
                    CurClaimItem.ClaimDetailType = ClaimManager.GetClaimDetailTypeFromCode(Convert.ToInt32(ResultRow[this.DataStructrure.Tables.ClaimDetail.DetailType.ActualFieldName].ToString()));
                    CurClaimItem.ClaimDate = (ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimDate.ActualFieldName].ToString().Length > 0) ? DateTime.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimDate.ActualFieldName].ToString()) : DateTime.MinValue;
                    CurClaimItem.DateEnd = (ResultRow[this.DataStructrure.Tables.ClaimDetail.DateEnd.ActualFieldName].ToString().Length > 0) ? DateTime.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.DateEnd.ActualFieldName].ToString()) : DateTime.MinValue;
                    CurClaimItem.Description = ResultRow[this.DataStructrure.Tables.ClaimDetail.Description.ActualFieldName].ToString();
                    CurClaimItem.Country = new Country(
                        ResultRow[this.DataStructrure.Tables.ClaimDetail.CountryCode.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLang.CountryName.ActualFieldName].ToString());
                    CurClaimItem.City = ResultRow[this.DataStructrure.Tables.ClaimDetail.City.ActualFieldName].ToString();

                    if (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName].ToString().Length > 0)
                    {
                        CurClaimItem.ClaimedAmountCurrency = new Currency(
                            ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName].ToString());
                    }

                    CurClaimItem.ClaimedAmount = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimed.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimed.ActualFieldName].ToString()) : 0;

                    if (ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName].ToString().Length > 0)
                    {
                        CurClaimItem.ExchangeCurrency = new Currency(
                            ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName].ToString());
                    }

                    CurClaimItem.ExchangeRate = (ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRateFigure.ActualFieldName].ToString().Length > 0) ? float.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRateFigure.ActualFieldName].ToString()) : 0;

                    if (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName].ToString().Length > 0)
                    {
                        CurClaimItem.AmountOutCurrency = new Currency(
                                ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName].ToString(),
                                ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName].ToString());
                    }

                    CurClaimItem.AmountOut = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOut.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOut.ActualFieldName].ToString()) : 0;
                    CurClaimItem.AmountFinal = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountFinal.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountFinal.ActualFieldName].ToString()) : 0;
                    CurClaimItem.Tax = (ResultRow[this.DataStructrure.Tables.ClaimDetail.Tax.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.Tax.ActualFieldName].ToString()) : 0;
                    CurClaimItem.Remarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.Remarks.ActualFieldName].ToString();
                    CurClaimItem.ApproverRemarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.ApproverRemarks.ActualFieldName].ToString();
                    CurClaimItem.ApproverState = (ResultRow[this.DataStructrure.Tables.ClaimDetail.ApproverState.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.AuthorizerRemarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.AuthorizerRemarks.ActualFieldName].ToString();
                    CurClaimItem.AuthorizerState = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AuthorizerState.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.FinanceRemarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.FIRemarks.ActualFieldName].ToString();
                    CurClaimItem.FinanceState = (ResultRow[this.DataStructrure.Tables.ClaimDetail.FinanceState.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.HavingPopOut = (ResultRow[this.DataStructrure.Tables.ClaimDetail.OtherReff.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.HavingReceipts = (ResultRow[this.DataStructrure.Tables.ClaimDetail.IsReceipts.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.ProjectID = ResultRow[this.DataStructrure.Tables.ClaimDetail.ProjectID.ActualFieldName].ToString();
                    CurClaimItem.ChargeToProfitCenter = ResultRow[this.DataStructrure.Tables.ClaimDetail.ChargeToProfitCenter.ActualFieldName].ToString();
                    CurClaimItem.ChargeToEmployeeiD = ResultRow[this.DataStructrure.Tables.ClaimDetail.ChargeToEmployeeID.ActualFieldName].ToString();
                    CurClaimItem.ActualExchangeRate = Convert.ToDecimal(ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLang.ActualExchangeRate.ActualFieldName]);

                    // finalize, add into the collection
                    ResultClaimItems.Add(CurClaimItem);
                }
            }

            return ResultClaimItems;
        }
        #endregion

        #region GetSimpleClaimItemsByClaimHeaderWithWeeklyLmit
        public ClaimItems GetSimpleClaimItemsByClaimHeaderWithWeeklyLmit(string ClaimInternalID, string ClaimantID)
        {
            ClaimItems ResultClaimItems = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithWeeklyLimit.Param_ClaimID.ActualFieldName, ClaimInternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithWeeklyLimit.Param_EmployeeID.ActualFieldName, ClaimantID));

            this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithWeeklyLimit.ActualTableName, KeyParameters);

            DataTable ResultTable = null;

            if (this.TryConnection())
            {

                ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable == null)
                {
                    this.CurrentLogManager.LogError("[ClaimManager.GetSimpleClaimItemsByClaimHeaderWithWeeklyLmit] : " + this.CurDBEngine.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }

            // start to load if nothing wrong
            if (ResultTable != null)
            {
                ResultClaimItems = new ClaimItems();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    GonzalesClaimItemWithWeeklyLimit CurClaimItem = new GonzalesClaimItemWithWeeklyLimit(ResultRow[this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName].ToString());

                    CurClaimItem.Order = Convert.ToInt32(ResultRow[this.DataStructrure.Tables.ClaimDetail.Order.ActualFieldName].ToString());
                    
                    // added in these 2
                    CurClaimItem.WeekInYear = Convert.ToInt32(ResultRow[this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithWeeklyLimit.WeekInYear.ActualFieldName]);
                    CurClaimItem.TotalSpentInWeek = (ResultRow[this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithWeeklyLimit.TotalSpentInWeek.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithWeeklyLimit.TotalSpentInWeek.ActualFieldName]) : 0;
                    CurClaimItem.AmountOut = (ResultRow[this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithWeeklyLimit.AmountOut.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithWeeklyLimit.AmountOut.ActualFieldName]) : 0;

                    // finalize, add into the collection
                    ResultClaimItems.Add(CurClaimItem);
                }
            }

            return ResultClaimItems;
        }
        #endregion

        #region GetClaimItemsByClaimHeaderInLangWithWeeklyLmit
        public ClaimItems GetClaimItemsByClaimHeaderInLangWithWeeklyLmit(string ClaimInternalID, Language SpecificLanguage, string ClaimantID)
        {
            ClaimItems ResultClaimItems = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithWeeklyLimit.Param_ClaimID.ActualFieldName, ClaimInternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithWeeklyLimit.Param_Language.ActualFieldName, SpecificLanguage.InternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithWeeklyLimit.Param_ClaimantID.ActualFieldName, ClaimantID));

            this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithWeeklyLimit.ActualTableName, KeyParameters);

            DataTable ResultTable = null;

            if (this.TryConnection())
            {

                ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable == null)
                {
                    this.CurrentLogManager.LogError("[ClaimManager.GetClaimItemsByClaimHeaderInLang] : " + this.CurDBEngine.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }

            // start to load if nothing wrong
            if (ResultTable != null)
            {
                ResultClaimItems = new ClaimItems();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    GonzalesClaimItemWithWeeklyLimit CurClaimItem = new GonzalesClaimItemWithWeeklyLimit(ResultRow[this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName].ToString());
                    //CurClaimItem.IsPersonnal = (ResultRow[this.DataStructrure.Tables.ClaimDetail.IsPersonal.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.ParentID = ResultRow[this.DataStructrure.Tables.ClaimDetail.Parents.ActualFieldName].ToString();
                    CurClaimItem.ParentIDInFI = ResultRow[this.DataStructrure.Tables.ClaimDetail.ParentsInFI.ActualFieldName].ToString();

                    CurClaimItem.Order = Convert.ToInt32(ResultRow[this.DataStructrure.Tables.ClaimDetail.Order.ActualFieldName].ToString());
                    CurClaimItem.ClaimType = new ClaimType(
                        ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimType.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLang.ClaimTypeDescInLang.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLang.GLCode.ActualFieldName].ToString());
                    CurClaimItem.ClaimDetailType = ClaimManager.GetClaimDetailTypeFromCode(Convert.ToInt32(ResultRow[this.DataStructrure.Tables.ClaimDetail.DetailType.ActualFieldName].ToString()));
                    CurClaimItem.ClaimDate = (ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimDate.ActualFieldName].ToString().Length > 0) ? DateTime.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimDate.ActualFieldName].ToString()) : DateTime.MinValue;
                    CurClaimItem.DateEnd = (ResultRow[this.DataStructrure.Tables.ClaimDetail.DateEnd.ActualFieldName].ToString().Length > 0) ? DateTime.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.DateEnd.ActualFieldName].ToString()) : DateTime.MinValue;
                    CurClaimItem.Description = ResultRow[this.DataStructrure.Tables.ClaimDetail.Description.ActualFieldName].ToString();
                    CurClaimItem.Country = new Country(
                        ResultRow[this.DataStructrure.Tables.ClaimDetail.CountryCode.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLang.CountryName.ActualFieldName].ToString());
                    CurClaimItem.City = ResultRow[this.DataStructrure.Tables.ClaimDetail.City.ActualFieldName].ToString();

                    if (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName].ToString().Length > 0)
                    {
                        CurClaimItem.ClaimedAmountCurrency = new Currency(
                            ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName].ToString());
                    }

                    CurClaimItem.ClaimedAmount = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimed.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimed.ActualFieldName].ToString()) : 0;

                    if (ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName].ToString().Length > 0)
                    {
                        CurClaimItem.ExchangeCurrency = new Currency(
                            ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName].ToString());
                    }

                    CurClaimItem.ExchangeRate = (ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRateFigure.ActualFieldName].ToString().Length > 0) ? float.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.ExchangeRateFigure.ActualFieldName].ToString()) : 0;

                    if (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName].ToString().Length > 0)
                    {
                        CurClaimItem.AmountOutCurrency = new Currency(
                                ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName].ToString(),
                                ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName].ToString());
                    }

                    CurClaimItem.AmountOut = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOut.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountOut.ActualFieldName].ToString()) : 0;
                    CurClaimItem.AmountFinal = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountFinal.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountFinal.ActualFieldName].ToString()) : 0;
                    CurClaimItem.Tax = (ResultRow[this.DataStructrure.Tables.ClaimDetail.Tax.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.Tax.ActualFieldName].ToString()) : 0;
                    CurClaimItem.Remarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.Remarks.ActualFieldName].ToString();
                    CurClaimItem.ApproverRemarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.ApproverRemarks.ActualFieldName].ToString();
                    CurClaimItem.ApproverState = (ResultRow[this.DataStructrure.Tables.ClaimDetail.ApproverState.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.AuthorizerRemarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.AuthorizerRemarks.ActualFieldName].ToString();
                    CurClaimItem.AuthorizerState = (ResultRow[this.DataStructrure.Tables.ClaimDetail.AuthorizerState.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.FinanceRemarks = ResultRow[this.DataStructrure.Tables.ClaimDetail.FIRemarks.ActualFieldName].ToString();
                    CurClaimItem.FinanceState = (ResultRow[this.DataStructrure.Tables.ClaimDetail.FinanceState.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.HavingPopOut = (ResultRow[this.DataStructrure.Tables.ClaimDetail.OtherReff.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.HavingReceipts = (ResultRow[this.DataStructrure.Tables.ClaimDetail.IsReceipts.ActualFieldName].ToString().CompareTo("1") == 0);
                    CurClaimItem.ProjectID = ResultRow[this.DataStructrure.Tables.ClaimDetail.ProjectID.ActualFieldName].ToString();
                    CurClaimItem.ChargeToProfitCenter = ResultRow[this.DataStructrure.Tables.ClaimDetail.ChargeToProfitCenter.ActualFieldName].ToString();
                    CurClaimItem.ChargeToEmployeeiD = ResultRow[this.DataStructrure.Tables.ClaimDetail.ChargeToEmployeeID.ActualFieldName].ToString();
                    CurClaimItem.ActualExchangeRate = Convert.ToDecimal(ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLang.ActualExchangeRate.ActualFieldName]);

                    // added in these 2
                    CurClaimItem.WeekInYear = Convert.ToInt32(ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithWeeklyLimit.WeekInYear.ActualFieldName]);
                    CurClaimItem.TotalSpentInWeek = Convert.ToDecimal(ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithWeeklyLimit.TotalSpendInWeek.ActualFieldName]);

                    // finalize, add into the collection
                    ResultClaimItems.Add(CurClaimItem);
                }
            }

            return ResultClaimItems;
        }
        #endregion

        #region GetClaimItemsByClaimHeaderInLangWithBreakDown
        public GonzalesClaimItem GetClaimItemsByClaimHeaderInLangWithBreakDown(string ClaimInternalID, Language SpecificLanguage)
        {
            GonzalesClaimItem CurClaimItem = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.Param_ClaimItemID.ActualFieldName, ClaimInternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.Param_Language.ActualFieldName, SpecificLanguage.InternalID));

            this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.ActualTableName, KeyParameters);

            DataTable ResultTable = null;

            if (this.TryConnection())
            {

                ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable == null)
                {
                    this.ErrMsg = "[ClaimManager.GetClaimItemsByClaimHeaderInLangWithBreakDown] : " + this.CurDBEngine.ErrorMessage;
                }
            }

            // start to load if nothing wrong
            if (ResultTable != null)
            {
                DataRow ResultRow = ResultTable.Rows[0];

                    CurClaimItem = new GonzalesClaimItem(ResultRow[this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName].ToString());
                    //CurClaimItem.IsPersonnal = (ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.IsPersonal.ActualFieldName].ToString().CompareTo("1") == 0);                    
                    
                    CurClaimItem.ClaimType = new ClaimType(
                        ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.ClaimType.ActualFieldName].ToString(),
                        ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.ClaimTypeDescInLang.ActualFieldName].ToString());
                    CurClaimItem.ClaimDetailType = ClaimManager.GetClaimDetailTypeFromCode(Convert.ToInt32(ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.DetailType.ActualFieldName].ToString()));
                    CurClaimItem.ClaimDate = (ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.ClaimDate.ActualFieldName].ToString().Length > 0) ? DateTime.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.ClaimDate.ActualFieldName].ToString()) : DateTime.MinValue;
                    CurClaimItem.DateEnd = (ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.DateEnd.ActualFieldName].ToString().Length > 0) ? DateTime.Parse(ResultRow[this.DataStructrure.Tables.ClaimDetail.DateEnd.ActualFieldName].ToString()) : DateTime.MinValue;
                    CurClaimItem.Description = ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.Description.ActualFieldName].ToString();
                    CurClaimItem.Remarks = ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.Remarks.ActualFieldName].ToString();

                    if (ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName].ToString().Length > 0)
                    {
                        CurClaimItem.ClaimedAmountCurrency = new Currency(
                            ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.AmountClaimedCurrency.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.AmountClaimedCurrency.ActualFieldName].ToString());
                    }

                    CurClaimItem.ClaimedAmount = (ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.AmountClaimed.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimed.ActualFieldName].ToString()) : 0;
                    CurClaimItem.DailyRate = (ResultRow[this.DataStructrure.StoredProcedures.GetClaimDetailInLangWithBreakdown.DailyRate.ActualFieldName].ToString().Length > 0) ? Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.ClaimDetail.AmountClaimed.ActualFieldName].ToString()) : 0;

            }

            return CurClaimItem;
        }
        #endregion

        #region GetClaimItemsWithActualExRate
        public Dictionary<string, decimal> GetClaimItemsWithActualExRate(string CurrencyID, string ClaimID)
        {
            Dictionary<string, decimal> ResultKeyPairs = new Dictionary<string, decimal>();

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithActualExchangeRate.Param_TargettedCurrency.ActualFieldName, CurrencyID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithActualExchangeRate.Param_TargettedCurrency.ActualFieldName, ClaimID));

            if (this.TryConnection())
            {
                this.CurSQLFactory.ExecuteStoredProcedure(
                    this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithActualExchangeRate.ActualTableName,
                    KeyParameters);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    foreach (DataRow ResultRow in ResultTable.Rows)
                    {
                        ResultKeyPairs.Add(
                            ResultRow[this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithActualExchangeRate.DetailLineID.ActualFieldName].ToString(),
                            decimal.Parse(ResultRow[this.DataStructrure.StoredProcedures.GetSimpleClaimDetailWithActualExchangeRate.ExRate.ActualFieldName].ToString()));
                    }
                }
                else
                {
                    this.ErrMsg = "[ClaimManager.GetClaimItemsWithActualExRate] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;                     
                }
            }
            else
            {
                this.ErrMsg = "[ClaimManager.GetClaimItemsWithActualExRate] : Exception : " + this.ErrMsg;                     
            }           

            return ResultKeyPairs;
        }
        #endregion

        #region GetClaimByStatus

        public ClaimHeaders GetClaimByStatus(GonzalesClaimHeader.TypeOfClaimStatus Status)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            if (Status != GonzalesClaimHeader.TypeOfClaimStatus.Null)
            {
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(Status).ToString()));
            }

            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {                
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);
                
            }
            else
            {
                // log error
                this.ErrMsg = "[ClaimManager.GetClaimByStatus] : " + this.ErrMsg;
            }

            return ResultClaimHeaders;
        }

        public ClaimHeaders GetClaimByStatus(GonzalesClaimHeader.TypeOfClaimStatus Status, SystemUser Owner)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            if (Status != GonzalesClaimHeader.TypeOfClaimStatus.Null)
            {
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(Status).ToString()));
            }
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.ClaimBy.ActualFieldName, Owner.InternalID));

            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);

            }
            else
            {
                // log error
                this.ErrMsg = "[ClaimManager.GetClaimByStatus] : " + this.ErrMsg;
            }

            return ResultClaimHeaders;
        }

        public ClaimHeaders GetClaimByStatus(GonzalesClaimHeader.TypeOfClaimStatus Status, SystemUser Owner, int Year)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();

            if (Status != GonzalesClaimHeader.TypeOfClaimStatus.Null)
            {
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(Status).ToString()));
            }

            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.ClaimBy.ActualFieldName, Owner.InternalID));
            KeyParameters.Add(new DatabaseParameter("YEAR(" + this.DataStructrure.Views.OpClaimHeaders.DateCreated.ActualFieldName + ")", Year.ToString()));

            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);

            }
            else
            {
                // log error
                this.ErrMsg = "[ClaimManager.GetClaimByStatus] : " + this.ErrMsg;
            }

            return ResultClaimHeaders;
        }

        public ClaimHeaders GetClaimByStatus(GonzalesClaimHeader.TypeOfClaimStatus Status, GonzalesCompany ClaimCompany)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            if (Status != GonzalesClaimHeader.TypeOfClaimStatus.Null)
            {
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(Status).ToString()));
            }

            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.Company.ActualFieldName, ClaimCompany.InternalID));

            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);

            }
            else
            {
                // log error
                this.ErrMsg = "[ClaimManager.GetClaimByStatus] : " + this.ErrMsg;
            }

            return ResultClaimHeaders;
        }

        #endregion

        #region GetClaimByDateRange

        public DataTable GetClaimByDateRange(string CompanyID, DateTime SubmittedDateStart, DateTime SubmittedDateEnd)
        {
            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsDetail.CompanyID.ActualFieldName, CompanyID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsDetail.DateLastUpdated.ActualFieldName, SubmittedDateStart, DBLinkage.AND, DBCompareType.LargerNEqual));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsDetail.DateLastUpdated.ActualFieldName, SubmittedDateEnd, DBLinkage.AND, DBCompareType.SmallerNEqual));

            this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructrure.Views.GeneralReportsDetail.ActualTableName);

            DataTable ResultTable = null;

            if (this.TryConnection())
            {

                ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable == null)
                {
                    this.CurrentLogManager.LogError("[ClaimManager.GetClaimItemsByClaimHeaderInLang] : " + this.CurDBEngine.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }


            return ResultTable;
        }

        #endregion

        #region GetClaimByDateRangeV1

        public ClaimHeaders GetClaimByDateRangeV1(string CompanyID, DateTime SubmittedDateStart, DateTime SubmittedDateEnd)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.Company.ActualFieldName, CompanyID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.DateSubmitted.ActualFieldName, SubmittedDateStart, DBLinkage.AND, DBCompareType.LargerNEqual));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.DateSubmitted.ActualFieldName, SubmittedDateEnd, DBLinkage.AND, DBCompareType.SmallerNEqual));

            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);

            }
            else
            {
                // log error
                this.ErrMsg = "[ClaimManager.GetClaimByDateRange] : " + this.ErrMsg;
            }

            return ResultClaimHeaders;
        }

        #endregion

        //Added by Geok Wiew [26 Aug 2011]
        #region GetClaimByDateRangeV2

        public DataTable GetClaimByDateRangeV2(string CompanyID, DateTime SubmittedDateStart, DateTime SubmittedDateEnd)
        {
            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsDetailApprover.CompanyID.ActualFieldName, CompanyID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsDetailApprover.DateLastUpdated.ActualFieldName, SubmittedDateStart, DBLinkage.AND, DBCompareType.LargerNEqual));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsDetailApprover.DateLastUpdated.ActualFieldName, SubmittedDateEnd, DBLinkage.AND, DBCompareType.SmallerNEqual));

            this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructrure.Views.GeneralReportsDetailApprover.ActualTableName);

            DataTable ResultTable = null;

            if (this.TryConnection())
            {

                ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable == null)
                {
                    this.CurrentLogManager.LogError("[ClaimManager.GetClaimItemsByClaimHeaderInLang] : " + this.CurDBEngine.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }


            return ResultTable;
        }

        #endregion

        #region GetClaimByDateRangeSummary

        public DataTable GetClaimByDateRangeSummary(string CompanyID, DateTime SubmittedDateStart, DateTime SubmittedDateEnd)
        {
            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsSummary.CompanyID.ActualFieldName, CompanyID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsSummary.DateLastUpdated.ActualFieldName, SubmittedDateStart, DBLinkage.AND, DBCompareType.LargerNEqual));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsSummary.DateLastUpdated.ActualFieldName, SubmittedDateEnd, DBLinkage.AND, DBCompareType.SmallerNEqual));

            this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructrure.Views.GeneralReportsSummary.ActualTableName);

            DataTable ResultTable = null;

            if (this.TryConnection())
            {

                ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable == null)
                {
                    this.CurrentLogManager.LogError("[ClaimManager.GetClaimByDateRangeSummary] : " + this.CurDBEngine.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }


            return ResultTable;
        }

        #endregion

        //Added by Geok Wiew [26 Aug 2011]
        #region GetClaimByDateRangeSummaryV2

        public DataTable GetClaimByDateRangeSummaryV2(string CompanyID, DateTime SubmittedDateStart, DateTime SubmittedDateEnd)
        {
            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsSummaryApprover.CompanyID.ActualFieldName, CompanyID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsSummaryApprover.DateLastUpdated.ActualFieldName, SubmittedDateStart, DBLinkage.AND, DBCompareType.LargerNEqual));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.GeneralReportsSummaryApprover.DateLastUpdated.ActualFieldName, SubmittedDateEnd, DBLinkage.AND, DBCompareType.SmallerNEqual));

            this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructrure.Views.GeneralReportsSummaryApprover.ActualTableName);

            DataTable ResultTable = null;

            if (this.TryConnection())
            {

                ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable == null)
                {
                    this.CurrentLogManager.LogError("[ClaimManager.GetClaimByDateRangeSummaryV2] : " + this.CurDBEngine.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }


            return ResultTable;
        }

        #endregion

        #region GetClaimItemLimitPolicies
        public ClaimTypeLimitPolicies GetClaimItemLimitPolicies(SystemUser Claimant, string ClaimInternalID)
        {
            ClaimTypeLimitPolicies ResultList = null;

            if (this.TryConnection())
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();                
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.Param_ClaimInternalID.ActualFieldName, ClaimInternalID));

                this.CurSQLFactory.ExecuteStoredProcedure(
                    this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.ActualTableName,
                    KeyParameters);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    ResultList = new ClaimTypeLimitPolicies();

                    foreach (DataRow ResultRow in ResultTable.Rows)
                    {
                        ClaimTypeLimitPolicy CurrentPolicy = new ClaimTypeLimitPolicy();
                        CurrentPolicy.ClaimDetalID = ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.ClaimDetailID.ActualFieldName].ToString();
                        CurrentPolicy.ClaimTypeInternalID = ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.ClaimTypeID.ActualFieldName].ToString();
                        CurrentPolicy.Duration = ClaimManager.GetClaimTypeLimitDurationFromCode(Convert.ToInt32(ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.Duration.ActualFieldName].ToString()));
                        CurrentPolicy.ExRateFigure = Convert.ToDecimal(ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.ExRateFigure.ActualFieldName].ToString());
                        CurrentPolicy.LimitAmount = Convert.ToDecimal(ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.AmountToLimit.ActualFieldName].ToString());
                        CurrentPolicy.LimitCurrency = new Currency(ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.CurrencyToLimit.ActualFieldName].ToString(), ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.CurrencyToLimit.ActualFieldName].ToString());
                        CurrentPolicy.LocalCurrency = new Currency(ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.LocalCurrency.ActualFieldName].ToString(), ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.LocalCurrency.ActualFieldName].ToString());
                        CurrentPolicy.Strict = (ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.IsStrict.ActualFieldName].ToString().CompareTo("1") == 0);
                        CurrentPolicy.TotalClaimedInPeriod = Convert.ToDecimal(ResultRow[this.DataStructrure.StoredProcedures.ValidateClaimTypeLimitPolicy.TotalClaimedInPeriod.ActualFieldName].ToString());
                        CurrentPolicy.UserInternalID = Claimant.InternalID;

                        ResultList.Add(CurrentPolicy);
                    }
                }
                else
                {
                    this.ErrMsg = "[ClaimManager.GetClaimItemLimitPolicies] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }

            }

            return ResultList;
        }
        #endregion

        #region GetFinanceApproverRemarks

        public FinanceApproverRemarks GetFinanceApproverRemarks(string FromUserID, string ClaimID)
        {
            FinanceApproverRemarks ResultCollection = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetFinancePersonnelRemarks.Param_ClaimID.ActualFieldName, ClaimID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetFinancePersonnelRemarks.Param_FromUserID.ActualFieldName, FromUserID));            

            if (this.TryConnection())
            {
                this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetFinancePersonnelRemarks.ActualTableName, KeyParameters);

                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    ResultCollection = new FinanceApproverRemarks();

                    foreach (DataRow ResultRow in ResultTable.Rows)
                    {
                        FinanceApproverRemark Remarks = new FinanceApproverRemark(ResultRow[this.DataStructrure.Tables.FinanceApproverRemarks.InternalID.ActualFieldName].ToString());

                        Remarks.Level = Convert.ToInt32(ResultRow[this.DataStructrure.Tables.FinanceApproverRemarks.Level.ActualFieldName]);
                        Remarks.Content = ResultRow[this.DataStructrure.Tables.FinanceApproverRemarks.Content.ActualFieldName].ToString();
                        Remarks.CreatedDateTime = Convert.ToDateTime(ResultRow[this.DataStructrure.Tables.FinanceApproverRemarks.CreatedDateTime.ActualFieldName].ToString());
                        Remarks.SendTo = new SystemUser(
                            ResultRow[this.DataStructrure.Views.FinanceApproverRemarks.RemarksTo.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.Views.FinanceApproverRemarks.RemarksTo.ActualFieldName].ToString());
                        Remarks.CreatedBy = new SystemUser(
                            ResultRow[this.DataStructrure.Views.FinanceApproverRemarks.RemarksBy.ActualFieldName].ToString(),
                            ResultRow[this.DataStructrure.Views.FinanceApproverRemarks.FAEmployeeDisplayName.ActualFieldName].ToString());

                        Remarks.CreatedBy.EmployeeID = ResultRow[this.DataStructrure.Views.FinanceApproverRemarks.FAEmployeeID.ActualFieldName].ToString();
                        Remarks.CreatedBy.Email = ResultRow[this.DataStructrure.Views.FinanceApproverRemarks.FAEmail.ActualFieldName].ToString();

                        ResultCollection.Add(Remarks);

                    }

                }
                else
                {
                    this.ErrMsg = "[ClaimManager.GetFinanceApproverRemarks] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                this.ErrMsg = "[ClaimManager.GetFinanceApproverRemarks] : " + this.ErrMsg;
            }

            return ResultCollection;
        }

        #endregion        

        #region CreateNewClaimID
        public string CreateNewClaimID(string EntityID)
        {
            string ResultID = "";

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.CreateNewClaimID.Param_EntityID.ActualFieldName, EntityID));

            if (this.TryConnection())
            {
                this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.CreateNewClaimID.ActualTableName, KeyParameters);
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null && ResultTable.Rows.Count == 1)
                {
                    ResultID = ResultTable.Rows[0][this.DataStructrure.StoredProcedures.CreateNewClaimID.ClaimID.ActualFieldName].ToString();
                }
                else
                {
                    this.ErrMsg = "[CreateNewClaimID] : Exception : " + this.ErrMsg;
                }
            }

            return ResultID;
        }
        #endregion

        #region *** Entertainment ***

        public EntertainmentHeader GetEntertainmentHeader(string ClaimID, string ClaimItemID)
        {
            EntertainmentHeader ResultObj = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add (new DatabaseParameter(this.DataStructrure.Tables.EntertainmentHeader.ClaimID.ActualFieldName, ClaimID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentHeader.ClaimItemID.ActualFieldName, ClaimItemID));

            if (this.TryConnection())
            {
                this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructrure.Tables.EntertainmentHeader.ActualTableName);
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    if (ResultTable.Rows.Count == 1)
                    {
                        ResultObj = new EntertainmentHeader(ResultTable.Rows[0][this.DataStructrure.Tables.EntertainmentHeader.InternalID.ActualFieldName].ToString());
                        ResultObj.Purpose = ResultTable.Rows[0][this.DataStructrure.Tables.EntertainmentHeader.Purpose.ActualFieldName].ToString();
                        ResultObj.GovOfficial = (ResultTable.Rows[0][this.DataStructrure.Tables.EntertainmentHeader.GovOfficial.ActualFieldName].ToString().CompareTo("1") == 0);
                        ResultObj.TotalCost = Convert.ToDecimal(ResultTable.Rows[0][this.DataStructrure.Tables.EntertainmentHeader.TotalCost.ActualFieldName]);
                    }
                }
                else
                {
                    this.ErrMsg = "[ClaimManager.GetEntertainmentHeader] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                this.ErrMsg = "[ClaimManager.GetEntertainmentHeader] : Exception : " + this.ErrMsg;
            }

            return ResultObj;
        }

        public EntertainmentDetails GetEntertainmentDetails(string EntID)
        {
            EntertainmentDetails ResultObj = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentDetail.EntID.ActualFieldName, EntID));            

            if (this.TryConnection())
            {
                this.CurSQLFactory.SelectCommand(KeyParameters, this.DataStructrure.Tables.EntertainmentDetail.ActualTableName);
                DataTable ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                if (ResultTable != null)
                {
                    ResultObj = new EntertainmentDetails();

                    foreach (DataRow ResultRow in ResultTable.Rows)
                    {
                        EntertainmentDetail CurrentObj = new EntertainmentDetail(ResultRow[this.DataStructrure.Tables.EntertainmentDetail.InternalID.ActualFieldName].ToString());
                        CurrentObj.Attendess = ResultRow[this.DataStructrure.Tables.EntertainmentDetail.Attendees.ActualFieldName].ToString();
                        CurrentObj.Company = ResultRow[this.DataStructrure.Tables.EntertainmentDetail.Company.ActualFieldName].ToString();
                        CurrentObj.Title = ResultRow[this.DataStructrure.Tables.EntertainmentDetail.Title.ActualFieldName].ToString();
                        CurrentObj.Order = Convert.ToInt32(ResultRow[this.DataStructrure.Tables.EntertainmentDetail.Order.ActualFieldName]);
                        CurrentObj.CostPerHead = Convert.ToDecimal(ResultRow[this.DataStructrure.Tables.EntertainmentDetail.CostPerHead.ActualFieldName]);

                        ResultObj.Add(CurrentObj);
                    }
                }
                else
                {
                    this.ErrMsg = "[ClaimManager.GetEntertainmentDetails] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                this.ErrMsg = "[ClaimManager.GetEntertainmentDetails] : Exception : " + this.ErrMsg;
            }

            return ResultObj;
        }

        #endregion


        //Added by mei chze on 18072012

        #region GetClaimByCompanyID

        public ClaimHeaders GetClaimByCompanyID(string CompanyID)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.Company.ActualFieldName, CompanyID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.Status.ActualFieldName, (ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.Draft).ToString()),DBDataType.String ,DBLinkage.AND ,DBCompareType.NotEqual ));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Views.OpClaimHeaders.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.New).ToString(), DBDataType.String, DBLinkage.AND , DBCompareType.NotEqual));
            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);

            }
            else
            {
                // log error
                this.ErrMsg = "[ClaimManager.GetClaimByDateRange] : " + this.ErrMsg;
            }

            return ResultClaimHeaders;
        }

        #endregion

        #region GetClaimByInternalID
        public ClaimHeaders GetClaimByInternalID1(string ClaimID)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, ClaimID));

            DataTable ResultTable = this.QueryClaimHeader(KeyParameters);
            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);

            }
            else
            {
                // log error
                this.ErrMsg = "[ClaimManager.GetClaimByID] : " + this.ErrMsg;
            }

            return ResultClaimHeaders;
        }

        #endregion

        #region GetClaimByID
        public ClaimHeaders GetClaimByID(string ClaimID, string entity, string company, string claimant)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimHeaderByID.para_ClaimID.ActualFieldName,ClaimID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimHeaderByID.para_CompanyName.ActualFieldName, company));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimHeaderByID.para_Entity.ActualFieldName, entity));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimHeaderByID.para_claimant.ActualFieldName, claimant));

            DataTable ResultTable = this.QueryClaimHeaderSP(KeyParameters);
            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);

            }
            else
            {
                // log error
                this.ErrMsg = "[ClaimManager.GetClaimByID] : " + this.ErrMsg;
            }

            return ResultClaimHeaders;
        }

        #endregion

        #region GetSubmittedClaimByApprover
        public ClaimHeaders GetClaimsByApprover(string ApproverInternalID, string company)
        {
            ClaimHeaders ResultClaimHeaders = null;

            DatabaseParametersGroup KeyParametersGroup = new DatabaseParametersGroup();

            // 1st Group
            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName, ApproverInternalID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Company.ActualFieldName, company));
            KeyParametersGroup.Add(KeyParameters);

            // 2nd Group
            KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.Submitted).ToString(), DBDataType.String, DBLinkage.OR));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.Escalated).ToString(), DBDataType.String, DBLinkage.OR));
            KeyParametersGroup.Add(KeyParameters);

            DataTable ResultTable = this.QueryClaimHeader(KeyParametersGroup);


            if (ResultTable != null)
            {
                ResultClaimHeaders = this.LoadClaimHeaders(ResultTable);
            }
            else
            {
                this.CurrentLogManager.LogError("[ClaimManager.GetClaimsByApprover] : " + this.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
            }

            return ResultClaimHeaders;
        }
        #endregion
        #endregion

        #region Actions

        #region *** Entertainment ***

        public bool SaveEntertainmentRemarks(EntertainmentHeader Entertainment, string ClaimID, string ClaimItemID)
        {
            bool smooth = true;
            ArrayList SQLList = new ArrayList();

            DatabaseParameters KeyParameters = new DatabaseParameters();
            DatabaseParameters ValParameters = new DatabaseParameters();

            #region 1. Clear entire entertainment data

            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentHeader.InternalID.ActualFieldName, Entertainment.InternalID));
            this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructrure.Tables.EntertainmentHeader.ActualTableName);
            SQLList.Add(this.CurSQLFactory.SQL);

            #endregion

            #region 2. Create new entertainment header

            KeyParameters.Clear();
            ValParameters.Clear();

            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentHeader.InternalID.ActualFieldName, Entertainment.InternalID));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentHeader.Purpose.ActualFieldName, Entertainment.Purpose.Replace("'", "''"), true, true));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentHeader.GovOfficial.ActualFieldName, ((Entertainment.GovOfficial) ? "1" : "0")));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentHeader.ClaimID.ActualFieldName, ClaimID));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentHeader.ClaimItemID.ActualFieldName, ClaimItemID));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentHeader.TotalCost.ActualFieldName, Entertainment.TotalCost.ToString()));

            this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.EntertainmentHeader.ActualTableName);
            SQLList.Add(this.CurSQLFactory.SQL);

            #endregion

            #region 3. Create entertainment detail

            if (Entertainment.Details != null)
            {
                for (int x = 0; x < Entertainment.Details.Count; x++)
                {
                    KeyParameters.Clear();
                    ValParameters.Clear();

                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentDetail.InternalID.ActualFieldName, Entertainment.Details[x].InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentDetail.EntID.ActualFieldName, Entertainment.InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentDetail.Attendees.ActualFieldName, Entertainment.Details[x].Attendess.Replace("'", "''"), true, true));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentDetail.Title.ActualFieldName, Entertainment.Details[x].Title.Replace("'", "''"), true, true));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentDetail.Company.ActualFieldName, Entertainment.Details[x].Company.Replace("'", "''"), true, true));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentDetail.Order.ActualFieldName, Entertainment.Details[x].Order.ToString()));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.EntertainmentDetail.CostPerHead.ActualFieldName, Entertainment.Details[x].CostPerHead.ToString()));

                    this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.EntertainmentDetail.ActualTableName);
                    SQLList.Add(this.CurSQLFactory.SQL);
                }
            }

            #endregion

            if (this.TryConnection())
            {
                if (!(smooth = this.CurDBEngine.ExecuteQuery(SQLList)))
                {
                    this.ErrMsg = "[ClaimManager.SaveEntertainmentRemarks] : Failed at this.CurDBEngine.SelectQuery() : " + this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                this.ErrMsg = "[ClaimManager.SaveEntertainmentRemarks] : Exception : " + this.ErrMsg;
            }

            return smooth;
        }

        #endregion

        #region CreateNewFinanceApproverRemarks

        public bool CreateNewFinanceApproverRemarks(FinanceApproverRemark Remark, string ClaimID)
        {
            bool smooth = true;

            DatabaseParameters ValParameters = new DatabaseParameters();
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.InternalID.ActualFieldName, Remark.InternalID));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.ClaimID.ActualFieldName, ClaimID));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.Content.ActualFieldName, Remark.Content.Replace("'", "''"), true, true));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.CreatedDateTime.ActualFieldName, Remark.CreatedDateTime));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.Level.ActualFieldName, Remark.Level.ToString()));
            ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.RemarksBy.ActualFieldName, Remark.CreatedBy.InternalID));

            if (Remark.SendTo != null)
            {
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.RemarksTo.ActualFieldName, Remark.SendTo.InternalID, true));
            }

            if (this.TryConnection())
            {
                this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Views.FinanceApproverRemarks.ActualTableName);

                if (!(smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL))) 
                {
                    this.ErrMsg = "[ClaimManager.CreateNewFinanceApproverRemarks] : Failed at this.CurDBEngine.ExecuteQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                this.ErrMsg = "[ClaimManager.CreateNewFinanceApproverRemarks] : " + this.ErrMsg;
            }


            return smooth;
        }

        #endregion

        #region DeleteFinanceApproverRemarks

        public bool DeleteFinanceApproverRemarks(string RemarkID)
        {
            bool smooth = true;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.InternalID.ActualFieldName, RemarkID));

            if (this.TryConnection())
            {
                this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructrure.Views.FinanceApproverRemarks.ActualTableName);

                if (!(smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL)))
                {
                    this.ErrMsg = "[ClaimManager.CreateNewFinanceApproverRemarks] : Failed at this.CurDBEngine.ExecuteQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                this.ErrMsg = "[ClaimManager.CreateNewFinanceApproverRemarks] : " + this.ErrMsg;
            }


            return smooth;
        }

        #endregion

        #region CreateNewClaim

        public bool CreateNewClaim(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            if (smooth)
            {
                DatabaseParameters ValParameters = new DatabaseParameters();

                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Reasons.ActualFieldName, TargettedClaimHeader.Reasons.Replace("'", "''"), true));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(TargettedClaimHeader.Status).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ClaimBy.ActualFieldName, TargettedClaimHeader.ClaimedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Company.ActualFieldName, TargettedClaimHeader.CompanyClaimedFrom.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Category.ActualFieldName, ClaimManager.GetClaimCategoryInCode(TargettedClaimHeader.Category).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateCreated.ActualFieldName, DateTime.Now));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, DateTime.Now));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LocalCurrency.ActualFieldName, TargettedClaimHeader.LocalCurrency.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DefaultCountry.ActualFieldName, TargettedClaimHeader.DefaultCountryCode));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DefaultCurrency.ActualFieldName, TargettedClaimHeader.DefaultCurrencyCode));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DefaultExchangeRate.ActualFieldName, TargettedClaimHeader.DefaultExchangeRate.ToString()));

                smooth = this.InsertClaimHeader(ValParameters);
                if (!smooth)
                {
                    // log the error
                    if (this.CurrentLogManager.IsReady)
                    {
                        this.CurrentLogManager.LogError("[CreateNewClaim:InsertClaimHeader] : " + this.ErrMsg, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                    }
                }
            }


            return smooth;
        }

        #endregion

        #region CancelClaimByClaimant

        public bool CancelClaimByClaimant(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;          

            try
            {                
                Jamila2.Database.DatabaseParameters KeyParameters = new Jamila2.Database.DatabaseParameters();
                Jamila2.Database.DatabaseParameters ValParameters = new Jamila2.Database.DatabaseParameters();

                KeyParameters.Add(new Jamila2.Database.DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new Jamila2.Database.DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(TargettedClaimHeader.Status).ToString()));

                smooth = this.UpdateClaimHeader(KeyParameters, ValParameters);
                if (!smooth)
                {
                    // log the error
                    if (this.CurrentLogManager.IsReady)
                    {
                        this.CurrentLogManager.LogError("[CancelClaimByClaimant:UpdateClaimHeader] : " + this.ErrMsg, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                    }
                }
            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = ex.Message;

                // log the error
                if (this.CurrentLogManager.IsReady)
                {
                    this.CurrentLogManager.LogError("[CancelClaimByClaimant] : " + this.ErrMsg, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }
           
            return smooth;
        }
        
        #endregion

        #region UpdateClaimByClaimant
        public bool UpdateClaimByClaimant(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;
                                               
            try
            {
                ArrayList SQLArray = new ArrayList();

                // Generate Header SQL
                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(TargettedClaimHeader.Status).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.ClaimedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, DateTime.Now));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Reasons.ActualFieldName, TargettedClaimHeader.Reasons.Replace("'", "''"), true));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ClaimedAmount.ActualFieldName, TargettedClaimHeader.TotalClaimedAmount.ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.TotalLocalAmountAlreadyPaid.ActualFieldName, TargettedClaimHeader.TotalLocalAmountAlreadyPaid.ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.TotalLocalAmountLeft.ActualFieldName, TargettedClaimHeader.TotalLocalActualAmountLeft.ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ChequeNo.ActualFieldName, TargettedClaimHeader.ChequeNo.ToString(), false, true));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.IssuedBank.ActualFieldName, TargettedClaimHeader.ChequeIssuesBank.ToString(), true, true));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ClaimID.ActualFieldName, TargettedClaimHeader.ClaimID, true));
                if(TargettedClaimHeader.ProjectedOn > DateTime.MinValue)
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, TargettedClaimHeader.ProjectedOn));

                if (TargettedClaimHeader.Status != GonzalesClaimHeader.TypeOfClaimStatus.Draft)
                {                    
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateSubmitted.ActualFieldName, TargettedClaimHeader.SubmittedOn));                    
                }

                if (TargettedClaimHeader.NextApprover != null)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName, TargettedClaimHeader.NextApprover.InternalID));
                }

                if (TargettedClaimHeader.NextAuthorizer != null)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextAuthorizer.ActualFieldName, TargettedClaimHeader.NextAuthorizer.InternalID));                    
                }

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // Delete all detail first
                KeyParameters.Clear();
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ClaimID.ActualFieldName, TargettedClaimHeader.InternalID));
                this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // Now, add in all detail
                for (int x = 0; x < TargettedClaimHeader.ClaimDetails.Count; x++)
                {
                    ValParameters.Clear();

                    GonzalesClaimItem CurrentClaimDetail = (GonzalesClaimItem)TargettedClaimHeader.ClaimDetails[x];

                    // Line Item Internal ID
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName, CurrentClaimDetail.InternalID));                    

                    // Claim Header Internal ID
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ClaimID.ActualFieldName, TargettedClaimHeader.InternalID));

                    // Claim Item Parent
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Parents.ActualFieldName, CurrentClaimDetail.ParentID, false, true));

                    // Order
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Order.ActualFieldName, CurrentClaimDetail.Order.ToString()));                    

                    // Claim Type
                    if (CurrentClaimDetail.ClaimType != null && CurrentClaimDetail.ClaimType.InternalID.Length > 0)
                    {
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ClaimType.ActualFieldName, CurrentClaimDetail.ClaimType.InternalID, false, true));
                    }

                    // Detail Type
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.DetailType.ActualFieldName, ClaimManager.GetClaimDetailTypeInCode(CurrentClaimDetail.ClaimDetailType).ToString()));

                    // Is Personal
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.IsPersonal.ActualFieldName, ((CurrentClaimDetail.IsPersonnal)?"1":"0")));

                    // Claim Date
                    if (CurrentClaimDetail.ClaimDate != DateTime.MinValue)
                    {
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ClaimDate.ActualFieldName, CurrentClaimDetail.ClaimDate));
                    }                    
                    
                    // Description
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Description.ActualFieldName, CurrentClaimDetail.Description.Replace("'", "''"), true));

                    // Remarks
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Remarks.ActualFieldName, CurrentClaimDetail.Remarks.Replace("'", "''"), true));

                    // Country
                    if (CurrentClaimDetail.Country != null)
                    {
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.CountryCode.ActualFieldName, CurrentClaimDetail.Country.InternalID));
                    }

                    // City
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.City.ActualFieldName, CurrentClaimDetail.City.Replace("'", "''"), true));

                    // Amount Claimed Currency
                    if (CurrentClaimDetail.ClaimedAmountCurrency != null)
                    {
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName, CurrentClaimDetail.ClaimedAmountCurrency.InternalID));
                    }

                    // Amount Claimed
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountClaimed.ActualFieldName, CurrentClaimDetail.ClaimedAmount.ToString()));

                    // Exchange Rate Currency = Amount Claimed Currency
                    if (CurrentClaimDetail.ExchangeCurrency != null)
                    {
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName, CurrentClaimDetail.ExchangeCurrency.InternalID));
                    }

                    // Exchange Rate Figure
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ExchangeRateFigure.ActualFieldName, Convert.ToDecimal(CurrentClaimDetail.ExchangeRate).ToString()));

                    // Tax
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Tax.ActualFieldName, CurrentClaimDetail.Tax.ToString()));

                    // Amount Out = Usually is local amount
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountOut.ActualFieldName, CurrentClaimDetail.AmountOut.ToString()));

                    // Amount Out Currency, normally is local currency
                    if (CurrentClaimDetail.AmountOutCurrency != null)
                    {
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName, CurrentClaimDetail.AmountOutCurrency.InternalID));
                    }

                    // Having Receipts?
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.IsReceipts.ActualFieldName, (CurrentClaimDetail.HavingReceipts?"1":"0")));
                    
                    // Project ID
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ProjectID.ActualFieldName, CurrentClaimDetail.ProjectID));

                    // Having Pop Out?
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.OtherReff.ActualFieldName, (CurrentClaimDetail.HavingPopOut?"1":"0")));

                    // *** Generate SQL Statement *** //
                    this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);
                    SQLArray.Add(this.CurSQLFactory.SQL);
                }


                // Start to update to database 
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);

                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByClaimant] : Failed at this.CurDBEngine.ExecuteQuery(SQLArray) : " + this.CurDBEngine.ErrorMessage;                        
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByClaimant] : Exception : " + ex.Message;
                
            }

            return smooth;
        }
        #endregion

        #region UpdateClaimByApprover
        public bool UpdateClaimByApprover(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;            

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(TargettedClaimHeader.Status).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));                
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName, TargettedClaimHeader.NextApprover.InternalID));

                if (TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.Approved || TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.PendingForAuthorize || TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.PendingForFinanceVerification)
                {   // mean approve
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ApprovedBy.ActualFieldName, TargettedClaimHeader.ApprovedBy.InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateApproved.ActualFieldName, TargettedClaimHeader.ApprovedOn));
                }

                if (TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByApprover)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, this.CurrentModuleSession.CurrentLoggedOnUser.InternalID));                    
                }

                if (TargettedClaimHeader.NextAuthorizer != null)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextAuthorizer.ActualFieldName, TargettedClaimHeader.NextAuthorizer.InternalID));
                }

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // detail
                for (int x = 0; x < TargettedClaimHeader.ClaimDetails.Count; x++)
                {
                    KeyParameters.Clear();
                    ValParameters.Clear();

                    KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName, TargettedClaimHeader.ClaimDetails[x].InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ApproverState.ActualFieldName, ((TargettedClaimHeader.ClaimDetails[x].ApproverState)?"1":"0")));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ApproverRemarks.ActualFieldName, TargettedClaimHeader.ClaimDetails[x].ApproverRemarks.Replace("'", "''"), true, true));

                    this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);
                    SQLArray.Add(this.CurSQLFactory.SQL);
                }

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }
                
            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;                                                   
            }

            return smooth;
        }
        #endregion

        #region UpdateClaimByAuthorizer
        public bool UpdateClaimByAuthorizer(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(TargettedClaimHeader.Status).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));                

                if (TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.PendingForFinanceVerification)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedBy.ActualFieldName, TargettedClaimHeader.AuthorizedBy.InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedOn.ActualFieldName, TargettedClaimHeader.AuthorizedOn));
                }

                if (TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByAuthorizer)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, this.CurrentModuleSession.CurrentLoggedOnUser.InternalID));
                }

                if (TargettedClaimHeader.NextFinanceAdmin != null)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, TargettedClaimHeader.NextFinanceAdmin.InternalID));
                }

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // detail
                for (int x = 0; x < TargettedClaimHeader.ClaimDetails.Count; x++)
                {
                    KeyParameters.Clear();
                    ValParameters.Clear();

                    GonzalesClaimItem CurrentDetailItem = (GonzalesClaimItem)TargettedClaimHeader.ClaimDetails[x];

                    KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName, TargettedClaimHeader.ClaimDetails[x].InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AuthorizerState.ActualFieldName, ((CurrentDetailItem.AuthorizerState) ? "1" : "0")));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AuthorizerRemarks.ActualFieldName, CurrentDetailItem.AuthorizerRemarks.Replace("'", "''"), true, true));

                    this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);
                    SQLArray.Add(this.CurSQLFactory.SQL);
                }

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByAuthorizer] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByAuthorizer] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateClaimByFinance
        public bool UpdateClaimByFinance(GonzalesClaimHeader TargettedClaimHeader, FinanceApproverRemark Remark)
        {
            bool smooth = true;            

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                #region Claim Header

                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(TargettedClaimHeader.Status).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinalAmount.ActualFieldName, TargettedClaimHeader.FinalApprovedAmount.ToString()));                
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.TotalLocalAmountAlreadyPaid.ActualFieldName, TargettedClaimHeader.TotalLocalAmountAlreadyPaid.ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.TotalLocalAmountLeft.ActualFieldName, TargettedClaimHeader.TotalLocalActualAmountLeft.ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));

                if (TargettedClaimHeader.ProjectedOn != DateTime.MinValue)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, TargettedClaimHeader.ProjectedOn));
                }

                if (TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.Processed || TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.SubmittedForPayment || TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.Verified)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, TargettedClaimHeader.ProcessedBy.InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, TargettedClaimHeader.ProcessedOn));
                }

                if (TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.OnHold)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldBy.ActualFieldName, TargettedClaimHeader.OnHoldBy.InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldOn.ActualFieldName, TargettedClaimHeader.OnHoldOn));
                }

                if (TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinance)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DateTime.Now));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, this.CurrentModuleSession.CurrentLoggedOnUser.InternalID));
                }

                if (TargettedClaimHeader.NextFinanceApprover != null)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, TargettedClaimHeader.NextFinanceApprover.InternalID));
                }

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                #endregion

                #region Claim Detail

                for (int x = 0; x < TargettedClaimHeader.ClaimDetails.Count; x++)
                {
                    GonzalesClaimItem CurrentClaimDetail = (GonzalesClaimItem)TargettedClaimHeader.ClaimDetails[x];

                    KeyParameters.Clear();
                    ValParameters.Clear();

                    if (CurrentClaimDetail.IsNew)
                    {
                        #region this is a newly added item, from duplicate

                        // Line Item Internal ID
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName, CurrentClaimDetail.InternalID));

                        // Claim Header Internal ID
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ClaimID.ActualFieldName, TargettedClaimHeader.InternalID));

                        // Claim Item Parent
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Parents.ActualFieldName, CurrentClaimDetail.ParentID, false, true));

                        // Claim Item Parent FI
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ParentsInFI.ActualFieldName, CurrentClaimDetail.ParentIDInFI, false, true));

                        // Order
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Order.ActualFieldName, CurrentClaimDetail.Order.ToString()));

                        // Claim Type
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ClaimType.ActualFieldName, CurrentClaimDetail.ClaimType.InternalID));

                        // Detail Type
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.DetailType.ActualFieldName, ClaimManager.GetClaimDetailTypeInCode(CurrentClaimDetail.ClaimDetailType).ToString()));

                        // Is Personal
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.IsPersonal.ActualFieldName, ((CurrentClaimDetail.IsPersonnal) ? "1" : "0")));

                        // Claim Date
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ClaimDate.ActualFieldName, CurrentClaimDetail.ClaimDate));
                        
                        // Description
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Description.ActualFieldName, CurrentClaimDetail.Description.Replace("'", "''"), true));

                        // Remarks
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Remarks.ActualFieldName, CurrentClaimDetail.Remarks.Replace("'", "''"), true));

                        // Country
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.CountryCode.ActualFieldName, CurrentClaimDetail.Country.InternalID));                        

                        // City
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.City.ActualFieldName, CurrentClaimDetail.City.Replace("'", "''"), true));

                        // Amount Claimed Currency
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName, CurrentClaimDetail.ClaimedAmountCurrency.InternalID));
                        
                        // Amount Claimed
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountClaimed.ActualFieldName, CurrentClaimDetail.ClaimedAmount.ToString()));

                        // Exchange Rate Currency = Amount Claimed Currency
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName, CurrentClaimDetail.ExchangeCurrency.InternalID));                        

                        // Exchange Rate Figure
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ExchangeRateFigure.ActualFieldName, Convert.ToDecimal(CurrentClaimDetail.ExchangeRate).ToString()));

                        // Tax
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Tax.ActualFieldName, CurrentClaimDetail.Tax.ToString()));

                        // Amount Out = Usually is local amount
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountOut.ActualFieldName, CurrentClaimDetail.AmountOut.ToString()));

                        // Amount Out Currency, normally is local currency
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountOutCurrency.ActualFieldName, CurrentClaimDetail.AmountOutCurrency.InternalID));                        

                        // Having Receipts?
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.IsReceipts.ActualFieldName, (CurrentClaimDetail.HavingReceipts ? "1" : "0")));

                        // Project ID
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ProjectID.ActualFieldName, CurrentClaimDetail.ProjectID));

                        // Having Pop Out?
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.OtherReff.ActualFieldName, (CurrentClaimDetail.HavingPopOut ? "1" : "0")));

                        // charge to profit center
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ChargeToProfitCenter.ActualFieldName, CurrentClaimDetail.ChargeToProfitCenter));

                        // charge to employee id
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ChargeToEmployeeID.ActualFieldName, CurrentClaimDetail.ChargeToEmployeeiD));

                        // Finance State
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.FinanceState.ActualFieldName, ((CurrentClaimDetail.FinanceState) ? "1" : "0")));

                        // Finance Remarks
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.FIRemarks.ActualFieldName, CurrentClaimDetail.FinanceRemarks.Replace("'", "''"), true, true));

                        // Final Amount
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountFinal.ActualFieldName, CurrentClaimDetail.AmountFinal.ToString()));                        

                        this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);

                        #endregion
                    }
                    else if (CurrentClaimDetail.MarkForDelete)
                    {
                        #region this is to delete the claim detail

                        KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName, CurrentClaimDetail.InternalID));

                        this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);

                        #endregion
                    }
                    else
                    {
                        #region this is an update for the item

                        KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName, CurrentClaimDetail.InternalID));

                        // Finance State
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.FinanceState.ActualFieldName, ((CurrentClaimDetail.FinanceState) ? "1" : "0")));

                        // Finance Remarks
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.FIRemarks.ActualFieldName, CurrentClaimDetail.FinanceRemarks.Replace("'", "''"), true, true));

                        // Final Amount
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountFinal.ActualFieldName, CurrentClaimDetail.AmountFinal.ToString()));

                        // Order
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Order.ActualFieldName, CurrentClaimDetail.Order.ToString()));

                        // Claim Type
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ClaimType.ActualFieldName, CurrentClaimDetail.ClaimType.InternalID));

                        // Amount Claimed Currency
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountClaimedCurrency.ActualFieldName, CurrentClaimDetail.ClaimedAmountCurrency.InternalID));

                        // Exchange Rate Currency = Amount Claimed Currency
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ExchangeRate.ActualFieldName, CurrentClaimDetail.ExchangeCurrency.InternalID));

                        // Exchange Rate Figure
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ExchangeRateFigure.ActualFieldName, Convert.ToDecimal(CurrentClaimDetail.ExchangeRate).ToString()));

                        // Tax
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.Tax.ActualFieldName, CurrentClaimDetail.Tax.ToString()));

                        // Project ID
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ProjectID.ActualFieldName, CurrentClaimDetail.ProjectID));

                        // charge to profit center
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ChargeToProfitCenter.ActualFieldName, CurrentClaimDetail.ChargeToProfitCenter));

                        // charge to employee id
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ChargeToEmployeeID.ActualFieldName, CurrentClaimDetail.ChargeToEmployeeiD));

                        this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);

                        #endregion
                    }

                    SQLArray.Add(this.CurSQLFactory.SQL);
                }

                #endregion

                #region Remarks

                if (Remark != null)
                {
                    KeyParameters.Clear();
                    ValParameters.Clear();

                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.InternalID.ActualFieldName, Remark.InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.ClaimID.ActualFieldName, TargettedClaimHeader.InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.Content.ActualFieldName, Remark.Content.Replace("'", "''"), true, true));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.CreatedDateTime.ActualFieldName, Remark.CreatedDateTime));                    
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.RemarksBy.ActualFieldName, Remark.CreatedBy.InternalID));

                    if (Remark.SendTo != null)
                    {
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.RemarksTo.ActualFieldName, Remark.SendTo.InternalID, true));
                    }

                    this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.FinanceApproverRemarks.ActualTableName);
                    SQLArray.Add(this.CurSQLFactory.SQL);
                }

                #endregion

                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);

                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByFinance] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByFinance] : Exception : " + ex.Message;

            }

            return smooth;
        }
        #endregion

        #region UpdateClaimByFinanceApprover
        public bool UpdateClaimByFinanceApprover(GonzalesClaimHeader TargettedClaimHeader, FinanceApproverRemark Remark)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                #region Claim Header

                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(TargettedClaimHeader.Status).ToString()));                
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));

                if (TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.Processed)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                }

                if (TargettedClaimHeader.Status == GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApprover)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DateTime.Now));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, this.CurrentModuleSession.CurrentLoggedOnUser.InternalID));
                }

                if (TargettedClaimHeader.NextFinanceApprover != null)
                {
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, TargettedClaimHeader.NextFinanceApprover.InternalID));
                }

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                #endregion

                #region Remarks

                if (Remark != null)
                {
                    KeyParameters.Clear();
                    ValParameters.Clear();

                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.InternalID.ActualFieldName, Remark.InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.ClaimID.ActualFieldName, TargettedClaimHeader.InternalID));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.Content.ActualFieldName, Remark.Content.Replace("'", "''"), true, true));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.CreatedDateTime.ActualFieldName, Remark.CreatedDateTime));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.Level.ActualFieldName, Remark.Level.ToString()));
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.RemarksBy.ActualFieldName, Remark.CreatedBy.InternalID));

                    if (Remark.SendTo != null)
                    {
                        ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.FinanceApproverRemarks.RemarksTo.ActualFieldName, Remark.SendTo.InternalID, true));
                    }

                    this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.FinanceApproverRemarks.ActualTableName);
                    SQLArray.Add(this.CurSQLFactory.SQL);
                }

                #endregion

                if (this.TryConnection())
                {
                    if (!(smooth = this.CurDBEngine.ExecuteQuery(SQLArray)))
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByFinanceApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }
            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByFinanceApprover] : Exception : " + ex.Message;

            }

            return smooth;
        }
        #endregion

        #region DeleteClaimByClaimant
        public bool DeleteClaimByClaimant(string InternalID)
        {
            bool smooth = true;            

            try
            {                
                DatabaseParameters KeyParameters = new DatabaseParameters();                
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, InternalID));                

                smooth = this.DeleteClaimHeader(KeyParameters);
                if (!smooth)
                {
                    // log the error
                    if (this.CurrentLogManager.IsReady)
                    {
                        this.CurrentLogManager.LogError("[DeleteClaimByClaimant:DeleteClaimHeader] : " + this.ErrMsg, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                    }
                }
            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = ex.Message;

                // log the error
                if (this.CurrentLogManager.IsReady)
                {
                    this.CurrentLogManager.LogError("[DeleteClaimByClaimant] : " + this.ErrMsg, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }

            return smooth;
        }
        #endregion

        #region SaveAsNewFromCurrent
        public bool SaveAsNewFromCurrent(string OldClaimID, string NewClaimID)
        {
            bool smooth = true;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.SaveAsNew.Param_NewClaimID.ActualFieldName, NewClaimID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.SaveAsNew.Param_OldClaimID.ActualFieldName, OldClaimID));

            this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.SaveAsNew.ActualTableName, KeyParameters);

            if (this.TryConnection())
            {
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.CurrentLogManager.LogError("[ClaimManager.SaveAsNewFromCurrent] : " + this.CurDBEngine.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }


            return smooth;
        }
        #endregion   
        
        #region SaveAsNewFromCurrentWithCreditCardTransfer
        public bool SaveAsNewFromCurrentWithCreditCardTransfer(string OldClaimID, string NewClaimID)
        {
            bool smooth = true;

            DatabaseParameters KeyParameters = new DatabaseParameters();
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.SaveAsNewWithCreditCardTransfer.Param_NewClaimID.ActualFieldName, NewClaimID));
            KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.SaveAsNewWithCreditCardTransfer.Param_OldClaimID.ActualFieldName, OldClaimID));

            this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.SaveAsNewWithCreditCardTransfer.ActualTableName, KeyParameters);

            if (this.TryConnection())
            {
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.CurrentLogManager.LogError("[ClaimManager.SaveAsNewFromCurrentWithCreditCardTransfer] : " + this.CurDBEngine.ErrorMessage, this.CurrentModuleSession.CurrentLoggedOnUser, LogInterface.System);
                }
            }


            return smooth;
        }
        #endregion 

        #region Clone

        #region GonzalesClaimItem

        public GonzalesClaimItem Clone(GonzalesClaimItem OriginalClaimItem, bool NewID)
        {
            return (NewID) ? this.Clone(OriginalClaimItem, SwissArmy.UniqueID()) : this.Clone(OriginalClaimItem, OriginalClaimItem.InternalID);
        }

        public GonzalesClaimItem Clone(GonzalesClaimItem OriginalClaimItem, string NewID)
        {
            GonzalesClaimItem ClonedClaimItem = new GonzalesClaimItem(NewID);

            ClonedClaimItem.AmountFinal = OriginalClaimItem.AmountFinal;
            ClonedClaimItem.AmountOut = OriginalClaimItem.AmountOut;
            ClonedClaimItem.AmountOutCurrency = OriginalClaimItem.AmountOutCurrency;
            ClonedClaimItem.ChargeToEmployeeiD = OriginalClaimItem.ChargeToEmployeeiD;
            ClonedClaimItem.ChargeToProfitCenter = OriginalClaimItem.ChargeToProfitCenter;
            ClonedClaimItem.City = OriginalClaimItem.City;
            ClonedClaimItem.ClaimDate = OriginalClaimItem.ClaimDate;
            ClonedClaimItem.ClaimDetailType = OriginalClaimItem.ClaimDetailType;
            ClonedClaimItem.ClaimedAmount = OriginalClaimItem.ClaimedAmount;
            ClonedClaimItem.ClaimedAmountCurrency = OriginalClaimItem.ClaimedAmountCurrency;
            ClonedClaimItem.ClaimType = OriginalClaimItem.ClaimType;
            ClonedClaimItem.Country = OriginalClaimItem.Country;
            ClonedClaimItem.DailyRate = OriginalClaimItem.DailyRate;
            ClonedClaimItem.DateEnd = OriginalClaimItem.DateEnd;
            ClonedClaimItem.Description = OriginalClaimItem.Description;
            ClonedClaimItem.ExchangeCurrency = OriginalClaimItem.ExchangeCurrency;
            ClonedClaimItem.ExchangeRate = OriginalClaimItem.ExchangeRate;
            ClonedClaimItem.HavingPopOut = OriginalClaimItem.HavingPopOut;
            ClonedClaimItem.HavingReceipts = OriginalClaimItem.HavingReceipts;
            //ClonedClaimItem.IsPersonnal = OriginalClaimItem.IsPersonnal;
            ClonedClaimItem.Order = OriginalClaimItem.Order;
            ClonedClaimItem.ParentClaimHeaderID = OriginalClaimItem.ParentClaimHeaderID;
            ClonedClaimItem.ParentID = OriginalClaimItem.ParentID;
            ClonedClaimItem.ParentIDInFI = OriginalClaimItem.ParentIDInFI;
            ClonedClaimItem.ProjectID = OriginalClaimItem.ProjectID;
            ClonedClaimItem.Remarks = OriginalClaimItem.Remarks;
            ClonedClaimItem.Tax = OriginalClaimItem.Tax;

            return ClonedClaimItem;
        }

        #endregion

        #endregion

        //update by mei chze on 16072012
        #region UpdateClaimHeaderWhenEditApprover
        public bool UpdateClaimHeaderWhenEditApprover(string claimby, string oldApprover, string newApprover)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();
                //DatabaseParametersGroup KeysGroup = new DatabaseParametersGroup();
                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                #region Claim Header

                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ClaimBy.ActualFieldName, claimby));
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName, oldApprover));
                //KeysGroup.Add(KeyParameters);
                //KeyParameters = new DatabaseParameters();
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GetClaimStatusFromCode("2")).ToString()));
                //KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GetClaimStatusFromCode("3")).ToString(), DBLinkage.OR));
                //KeysGroup.Add(KeyParameters);
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName,newApprover));


                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                #endregion

                if (this.TryConnection())
                {
                    if (!(smooth = this.CurDBEngine.ExecuteQuery(SQLArray)))
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimHeaderWhenEditApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }
            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimHeaderWhenEditApprover] : Exception : " + ex.Message;

            }

            return smooth;
        }
        #endregion
        #region UpdateClaimHeaderWhenEditApprover1
        public bool UpdateClaimHeaderWhenEditApprover1(string claimby, string oldApprover, string newApprover)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();
                //DatabaseParametersGroup KeysGroup = new DatabaseParametersGroup();
                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                #region Claim Header

                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ClaimBy.ActualFieldName, claimby));
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName, oldApprover));
                //KeysGroup.Add(KeyParameters);
               // KeyParameters = new DatabaseParameters();
                //KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GetClaimStatusFromCode("2")).ToString()));
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GetClaimStatusFromCode("3")).ToString()));
                //KeysGroup.Add(KeyParameters);
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName, newApprover));


                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                #endregion

                if (this.TryConnection())
                {
                    if (!(smooth = this.CurDBEngine.ExecuteQuery(SQLArray)))
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimHeaderWhenEditApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }
            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimHeaderWhenEditApprover] : Exception : " + ex.Message;

            }

            return smooth;
        }
         #endregion

        #region GetClaimHeaderByClaimByAndClaimApprover
        public DataTable GetClaimHeaderByClaimByAndClaimApprover(string claimby, string oldApprover)
        {
            DataTable ResultTable = null;

            if (this.TryConnection())
            {
                DatabaseParameters KeyParameters = new DatabaseParameters();
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimHeaderByClaimByAndClaimApprover.para_ClaimBy.ActualFieldName, claimby));
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.StoredProcedures.GetClaimHeaderByClaimByAndClaimApprover.para_ClaimApprover.ActualFieldName, oldApprover));

                this.CurSQLFactory.ExecuteStoredProcedure(this.DataStructrure.StoredProcedures.GetClaimHeaderByClaimByAndClaimApprover.ActualTableName, KeyParameters);

                ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);
                if (ResultTable != null)
                {
                    //ResultUsers = new DataTable();

                    //foreach (DataRow ResultRow in ResultTable.Rows)
                    //{
                    //    Authoriser CurAuthoriser = this.SuperCast(this.LoadUser(ResultRow));

                    //    CurAuthoriser.Level = Convert.ToInt32(ResultRow[this.DataStructrure.StoredProcedures.GetAuthorizerByEntity.Level.ActualFieldName]);
                    //    CurAuthoriser.LimitCurrency = new Currency(
                    //        ResultRow[this.DataStructrure.StoredProcedures.GetAuthorizerByEntity.Currency.ActualFieldName].ToString(),
                    //        ResultRow[this.DataStructrure.StoredProcedures.GetAuthorizerByEntity.Currency.ActualFieldName].ToString());

                    //    CurAuthoriser.MinLimit = Convert.ToDecimal(ResultRow[this.DataStructrure.StoredProcedures.GetAuthorizerByEntity.MinAmount.ActualFieldName]);
                    //    CurAuthoriser.MaxLimit = Convert.ToDecimal(ResultRow[this.DataStructrure.StoredProcedures.GetAuthorizerByEntity.MaxAmount.ActualFieldName]);

                    //    ResultUsers.Add(CurAuthoriser);
                    //}

                }
                else
                {
                    this.ErrMsg = "[ClaimManager.GetClaimHeaderByClaimByAndClaimApprover] : Failure in this.CurDBEngine.SelectQuery: " + this.CurDBEngine.ErrorMessage;
                }
            }

            return ResultTable;
        }
        #endregion
        #region UpdateClaimHeaderWhenChangeApprover
        public bool UpdateClaimHeaderWhenChangeApprover(string ClaimID, string newApprover)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                #region Claim Header

                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, ClaimID));
                 ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName, newApprover));
                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                #endregion

                if (this.TryConnection())
                {
                    if (!(smooth = this.CurDBEngine.ExecuteQuery(SQLArray)))
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimHeaderWhenChangeApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }
            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimHeaderWhenChangeApprover] : Exception : " + ex.Message;

            }

            return smooth;
        }
         #endregion

        #region UpdateWhenStatusChangeToSumitted
        public bool UpdateStatusChangeToSumitted(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.Submitted).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName, TargettedClaimHeader.NextApprover.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateApproved.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateEscalated.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextAuthorizer .ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, DBDataFormula.NULL));              

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);             

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateWhenStatusChangeToEscalated
        public bool UpdateWhenStatusChangeToEscalated(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.Escalated).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextApprover.ActualFieldName, TargettedClaimHeader.NextApprover.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateEscalated.ActualFieldName, TargettedClaimHeader.ProjectedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateApproved.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextAuthorizer.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, DBDataFormula.NULL));

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateWhenStatusChangeToPendingAuthorizer
        public bool UpdateWhenStatusChangeToPendingAuthorizer(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.PendingForAuthorize).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextAuthorizer.ActualFieldName, TargettedClaimHeader.NextAuthorizer.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));                
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, DBDataFormula.NULL));

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateWhenStatusChangeToPendingFinanceAdmin
        public bool UpdateWhenStatusChangeToPendingFinanceAdmin(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.PendingForFinanceVerification).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, DBDataFormula.NULL));

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateWhenStatusChangeToPendingforFinanceVerifier
        public bool UpdateWhenStatusChangeToPendingforFinanceVerifier(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.Verified).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName,TargettedClaimHeader.NextFinanceApprover.InternalID ));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, DBDataFormula.NULL));

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateWhenStatusChangeToOnHold
        public bool UpdateWhenStatusChangeToOnHold(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.OnHold).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldBy.ActualFieldName, TargettedClaimHeader.OnHoldBy.InternalID  ));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldOn.ActualFieldName, TargettedClaimHeader.OnHoldOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, DBDataFormula.NULL));

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateWhenStatusChangeToSubmitForPayment
        public bool UpdateWhenStatusChangeToSubmitForPayment(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.SubmittedForPayment).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, TargettedClaimHeader.ProcessedBy.InternalID ));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, TargettedClaimHeader.ProcessedOn ));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, DBDataFormula.NULL));

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateWhenStatusChangeRejectByApprover
        public bool UpdateStatusChangeRejectByApprover(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.RejectedByApprover).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateApproved.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateEscalated.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextAuthorizer.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, TargettedClaimHeader.NextApprover.InternalID));

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateWhenStatusChangeRejectByAuthorized
        public bool UpdateStatusChangeRejectByAuthorized(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.RejectedByApprover).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.AuthorizedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.OnHoldOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextAuthorizer.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, TargettedClaimHeader.AuthorizedBy.InternalID ));

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateWhenStatusChangeRejectByFinance
        public bool UpdateStatusChangeRejectByFinance(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinance ).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextAuthorizer.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, TargettedClaimHeader.NextFinanceApprover.InternalID));

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateWhenStatusChangeRejectByFinanceApprover
        public bool UpdateStatusChangeRejectByFinanceApprover(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                // header
                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.RejectedByFinanceApprover).ToString()));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.LastUpdatedBy.ActualFieldName, TargettedClaimHeader.LastUpdatedBy.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateLastUpdated.ActualFieldName, TargettedClaimHeader.LastUpdatedOn));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.FinanceApprovedOn.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFA.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextFinanceApproval.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.ProcessedBy.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProcessed.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateProjected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.DateRejected.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.NextAuthorizer.ActualFieldName, DBDataFormula.NULL));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.RejectedBy.ActualFieldName, TargettedClaimHeader.FinanceApprovedBy.InternalID));

                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                // real game
                if (this.TryConnection())
                {
                    smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                    if (!smooth)
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateDetailClaimWhenStatusChangeRejectByFinanceApprover
        public bool UpdateDetailClaimStatusChangeApprovedByFinanceApprover(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                for (int x = 0; x < TargettedClaimHeader.ClaimDetails.Count; x++)
                {
                    GonzalesClaimItem CurrentClaimDetail = (GonzalesClaimItem)TargettedClaimHeader.ClaimDetails[x];

                    KeyParameters.Clear();
                    ValParameters.Clear();


                    // header
                    #region this is an update for the item

                    KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.InternalID.ActualFieldName, CurrentClaimDetail.InternalID));

                    // Finance State
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.FinanceState.ActualFieldName, ((CurrentClaimDetail.FinanceState) ? "1" : "0")));

                    // Final Amount
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.AmountFinal.ActualFieldName, CurrentClaimDetail.AmountOut.ToString()));

                    // charge to profit center
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ChargeToProfitCenter.ActualFieldName, TargettedClaimHeader.ClaimedBy.CostCenter ));

                    // charge to employee id
                    ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimDetail.ChargeToEmployeeID.ActualFieldName, TargettedClaimHeader.ClaimedBy.EmployeeID));

                    this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);

                    #endregion
                    SQLArray.Add(this.CurSQLFactory.SQL);

                    // real game
                    if (this.TryConnection())
                    {
                        smooth = this.CurDBEngine.ExecuteQuery(SQLArray);
                        if (!smooth)
                        {
                            this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimByApprover] : Exception : " + ex.Message;
            }

            return smooth;
        }
        #endregion

        #region UpdateClaimHeaderWhenCancelled
        public bool UpdateClaimHeaderWhenCancelled(GonzalesClaimHeader TargettedClaimHeader)
        {
            bool smooth = true;

            try
            {
                ArrayList SQLArray = new ArrayList();

                DatabaseParameters KeyParameters = new DatabaseParameters();
                DatabaseParameters ValParameters = new DatabaseParameters();

                #region Claim Header

                KeyParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.InternalID.ActualFieldName, TargettedClaimHeader.InternalID));
                ValParameters.Add(new DatabaseParameter(this.DataStructrure.Tables.ClaimHeader.Status.ActualFieldName, ClaimManager.GetClaimStatusInCode(GonzalesClaimHeader.TypeOfClaimStatus.Cancelled).ToString()));
                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                SQLArray.Add(this.CurSQLFactory.SQL);

                #endregion

                if (this.TryConnection())
                {
                    if (!(smooth = this.CurDBEngine.ExecuteQuery(SQLArray)))
                    {
                        this.ErrMsg = "[ClaimManager.UpdateClaimHeaderWhenEditApprover] : Failed at this.CurDBEngine.ExecuteQuery() : " + this.CurDBEngine.ErrorMessage;
                    }
                }
            }
            catch (Exception ex)
            {
                smooth = false;
                this.ErrMsg = "[ClaimManager.UpdateClaimHeaderWhenEditApprover] : Exception : " + ex.Message;

            }

            return smooth;
        }
        #endregion
        #endregion

        #region Protected Methods

        #region LoadClaimHeader
        protected GonzalesClaimHeader LoadClaimHeader(DataRow ResultRow)
        {
            GonzalesClaimHeader ResultHeader = null;

            ResultHeader = new GonzalesClaimHeader(
                ResultRow[this.DataStructrure.Views.OpClaimHeaders.InternalID.ActualFieldName].ToString(),
                ResultRow[this.DataStructrure.Views.OpClaimHeaders.Reasons.ActualFieldName].ToString());

            // approved claim
            if (ResultRow[this.DataStructrure.Views.OpClaimHeaders.ApprovedBy.ActualFieldName].ToString().Length > 0)
            {
                ResultHeader.ApprovedBy = new SystemUser(
                    ResultRow[this.DataStructrure.Views.OpClaimHeaders.ApprovedBy.ActualFieldName].ToString(), 
                    ResultRow[this.DataStructrure.Views.OpClaimHeaders.ApprovedByPersonnel.ActualFieldName].ToString());
                ResultHeader.ApprovedOn = DateTime.Parse(ResultRow[this.DataStructrure.Views.OpClaimHeaders.DateApproved.ActualFieldName].ToString());
            }

            // claimant
            ResultHeader.ClaimedBy = new SystemUser(
                ResultRow[this.DataStructrure.Views.OpClaimHeaders.ClaimBy.ActualFieldName].ToString(), 
                ResultRow[this.DataStructrure.Views.OpClaimHeaders.ClaimantName.ActualFieldName].ToString());
            ResultHeader.ClaimedBy.Email = ResultRow[this.DataStructrure.Views.OpClaimHeaders.ClaimantEmail.ActualFieldName].ToString();
            ResultHeader.ClaimedBy.EmailID = ResultRow[this.DataStructrure.Views.OpClaimHeaders.ClaimantEmailID.ActualFieldName].ToString();
            ResultHeader.ClaimedBy.EmployeeID = ResultRow[this.DataStructrure.Views.OpClaimHeaders.ClaimantEmployeeID.ActualFieldName].ToString();
            ResultHeader.ClaimedBy.CostCenter = ResultRow[this.DataStructrure.Views.OpClaimHeaders.ClaimantCostCenter.ActualFieldName].ToString();

            // company
            ResultHeader.CompanyClaimedFrom = new GonzalesCompany(
                ResultRow[this.DataStructrure.Views.OpClaimHeaders.Company.ActualFieldName].ToString(),
                ResultRow[this.DataStructrure.Views.OpClaimHeaders.ClaimantName.ActualFieldName].ToString());

            ResultHeader.CreatedOn = DateTime.Parse(ResultRow[this.DataStructrure.Views.OpClaimHeaders.DateCreated.ActualFieldName].ToString());
            ResultHeader.FinalApprovedAmount = Convert.ToDecimal(ResultRow[this.DataStructrure.Views.OpClaimHeaders.FinalAmount.ActualFieldName].ToString());

            // last updated
            ResultHeader.LastUpdatedBy = new SystemUser(
                ResultRow[this.DataStructrure.Views.OpClaimHeaders.LastUpdatedBy.ActualFieldName].ToString(),
                ResultRow[this.DataStructrure.Views.OpClaimHeaders.LastUpdatedByPersonnel.ActualFieldName].ToString());
            ResultHeader.LastUpdatedOn = DateTime.Parse(ResultRow[this.DataStructrure.Views.OpClaimHeaders.DateLastUpdated.ActualFieldName].ToString());            

            // authorized by
            if (ResultRow[this.DataStructrure.Views.OpClaimHeaders.AuthorizedBy.ActualFieldName].ToString().Length > 0)
            {
                ResultHeader.AuthorizedBy = new SystemUser(
                    ResultRow[this.DataStructrure.Views.OpClaimHeaders.AuthorizedBy.ActualFieldName].ToString(),
                    ResultRow[this.DataStructrure.Views.OpClaimHeaders.AuthorizedByPersonnel.ActualFieldName].ToString());
                ResultHeader.AuthorizedOn = DateTime.Parse(ResultRow[this.DataStructrure.Views.OpClaimHeaders.AuthorizedOn.ActualFieldName].ToString());
            }

            // finance approved by
            if (ResultRow[this.DataStructrure.Views.OpClaimHeaders.FinanceApprovedBy.ActualFieldName].ToString().Length > 0)
            {
                ResultHeader.FinanceApprovedBy = new SystemUser(
                    ResultRow[this.DataStructrure.Views.OpClaimHeaders.FinanceApprovedBy.ActualFieldName].ToString(),
                    ResultRow[this.DataStructrure.Views.OpClaimHeaders.FinanceApprovedByPersonnel.ActualFieldName].ToString());
                ResultHeader.FinanceApprovedOn = DateTime.Parse(ResultRow[this.DataStructrure.Views.OpClaimHeaders.FinanceApprovedOn.ActualFieldName].ToString());
            }

            // Paid On dates
            if (ResultRow[this.DataStructrure.Views.OpClaimHeaders.PaidOn.ActualFieldName].ToString().Length > 0)
            {
                ResultHeader.PaidOn = DateTime.Parse(ResultRow[this.DataStructrure.Views.OpClaimHeaders.PaidOn.ActualFieldName].ToString());
            }

            // Submitted On dates
            if (ResultRow[this.DataStructrure.Views.OpClaimHeaders.DateSubmitted.ActualFieldName].ToString().Length > 0)
            {
                ResultHeader.SubmittedOn = DateTime.Parse(ResultRow[this.DataStructrure.Views.OpClaimHeaders.DateSubmitted.ActualFieldName].ToString());
            }

            // Processed On dates
            if (ResultRow[this.DataStructrure.Views.OpClaimHeaders.DateProcessed.ActualFieldName].ToString().Length > 0)
            {
                ResultHeader.ProcessedBy = new SystemUser(
                    ResultRow[this.DataStructrure.Views.OpClaimHeaders.ProcessedBy.ActualFieldName].ToString(),
                    ResultRow[this.DataStructrure.Views.OpClaimHeaders.ProcessedByPersonnel.ActualFieldName].ToString());
                ResultHeader.ProcessedOn = DateTime.Parse(ResultRow[this.DataStructrure.Views.OpClaimHeaders.DateProcessed.ActualFieldName].ToString());
            }

            // Projected On dates
            if (ResultRow[this.DataStructrure.Views.OpClaimHeaders.DateProjected.ActualFieldName].ToString().Length > 0)
            {
                ResultHeader.ProjectedOn = DateTime.Parse(ResultRow[this.DataStructrure.Views.OpClaimHeaders.DateProjected.ActualFieldName].ToString());
            }

            ResultHeader.Category = ClaimManager.GetClaimCategoryFromCode(ResultRow[this.DataStructrure.Views.OpClaimHeaders.Category.ActualFieldName].ToString());
            ResultHeader.ClaimID = ResultRow[this.DataStructrure.Views.OpClaimHeaders.ClaimID.ActualFieldName].ToString();
            ResultHeader.LocalCurrency = new Currency(ResultRow[this.DataStructrure.Views.OpClaimHeaders.LocalCurrency.ActualFieldName].ToString(), ResultRow[this.DataStructrure.Views.OpClaimHeaders.LocalCurrency.ActualFieldName].ToString());           
            ResultHeader.Reasons = ResultRow[this.DataStructrure.Views.OpClaimHeaders.Reasons.ActualFieldName].ToString();
            ResultHeader.Status = ClaimManager.GetClaimStatusFromCode(ResultRow[this.DataStructrure.Views.OpClaimHeaders.Status.ActualFieldName].ToString());
            ResultHeader.ChequeNo = ResultRow[this.DataStructrure.Views.OpClaimHeaders.ChequeNo.ActualFieldName].ToString();
            ResultHeader.ChequeIssuesBank = ResultRow[this.DataStructrure.Views.OpClaimHeaders.IssuedBank.ActualFieldName].ToString();
            ResultHeader.FinalApprovedAmount = Convert.ToDecimal(ResultRow[this.DataStructrure.Views.OpClaimHeaders.FinalAmount.ActualFieldName]);
            ResultHeader.TotalClaimedAmount = Convert.ToDecimal(ResultRow[this.DataStructrure.Views.OpClaimHeaders.ClaimedAmount.ActualFieldName]);
            ResultHeader.TotalLocalActualAmountLeft = Convert.ToDecimal(ResultRow[this.DataStructrure.Views.OpClaimHeaders.TotalLocalAmountLeft.ActualFieldName]);
            ResultHeader.TotalLocalAmountAlreadyPaid = Convert.ToDecimal(ResultRow[this.DataStructrure.Views.OpClaimHeaders.TotalLocalAmountAlreadyPaid.ActualFieldName]);

            ResultHeader.NextApprover = (ResultRow[this.DataStructrure.Views.OpClaimHeaders.NextApprover.ActualFieldName].ToString().Length == 36) ? new LoginUser(ResultRow[this.DataStructrure.Views.OpClaimHeaders.NextApprover.ActualFieldName].ToString()) : null;
            //added by agnes[31march2009] - for enhancement
            if(ResultRow[this.DataStructrure.Views.OpClaimHeaders.OnBehalfReview.ActualFieldName].ToString().Length > 0)
                ResultHeader.NextApprover.Email = ResultRow[this.DataStructrure.Views.OpClaimHeaders.OnBehalfReview.ActualFieldName].ToString();
            else if(ResultRow[this.DataStructrure.Views.OpClaimHeaders.NextApproverEmail.ActualFieldName].ToString().Length > 0)
                ResultHeader.NextApprover.Email = ResultRow[this.DataStructrure.Views.OpClaimHeaders.NextApproverEmail.ActualFieldName].ToString();

            ResultHeader.NextAuthorizer = (ResultRow[this.DataStructrure.Views.OpClaimHeaders.NextAuthorizer.ActualFieldName].ToString().Length == 36) ? new SystemUser(ResultRow[this.DataStructrure.Views.OpClaimHeaders.NextAuthorizer.ActualFieldName].ToString(), "") : null;
            ResultHeader.NextFinanceAdmin = (ResultRow[this.DataStructrure.Views.OpClaimHeaders.NextFA.ActualFieldName].ToString().Length == 36) ? new SystemUser(ResultRow[this.DataStructrure.Views.OpClaimHeaders.NextFA.ActualFieldName].ToString(), "") : null;
            ResultHeader.NextFinanceApprover = (ResultRow[this.DataStructrure.Views.OpClaimHeaders.NextFinanceApproval.ActualFieldName].ToString().Length == 36) ? new SystemUser(ResultRow[this.DataStructrure.Views.OpClaimHeaders.NextFinanceApproval.ActualFieldName].ToString(), "") : null;

            // Default variable
            ResultHeader.DefaultCountryCode = ResultRow[this.DataStructrure.Views.OpClaimHeaders.DefaultCountry.ActualFieldName].ToString();
            ResultHeader.DefaultCurrencyCode = ResultRow[this.DataStructrure.Views.OpClaimHeaders.DefaultCurrency.ActualFieldName].ToString();
            ResultHeader.DefaultExchangeRate = (ResultRow[this.DataStructrure.Views.OpClaimHeaders.DefaultExchangeRate.ActualFieldName].ToString().Length > 0) ? decimal.Parse(ResultRow[this.DataStructrure.Views.OpClaimHeaders.DefaultExchangeRate.ActualFieldName].ToString()) : 1;


            return ResultHeader;
        }
        #endregion

        #region LoadClaimHeaders
        protected ClaimHeaders LoadClaimHeaders(DataTable ResultTable)
        {
            ClaimHeaders ResultHeaders = null;

            if (ResultTable != null)
            {
                ResultHeaders = new ClaimHeaders();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    ResultHeaders.Add(this.LoadClaimHeader(ResultRow));
                }
            }

            return ResultHeaders;
        }
        #endregion

        #region QueryClaimHeader
        protected virtual DataTable QueryClaimHeader(DatabaseParameters Parameters)
        {
            DataTable ResultTable = null;

            this.CurSQLFactory.SelectCommand(Parameters, this.DataStructrure.Views.OpClaimHeaders.ActualTableName);

            if (this.TryConnection())
            {
                try
                {
                    ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                    if (ResultTable == null)
                    {
                        this.ErrMsg = "[ClaimManager.QueryClaimHeader] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                    }
                }
                catch (Exception ex)
                {
                    this.ErrMsg = ex.Message;
                }
            }
        

            return ResultTable;
        }

        protected virtual DataTable QueryClaimHeader(DatabaseParametersGroup ParametersGroup)
        {
            DataTable ResultTable = null;
            string[] Tables = {this.DataStructrure.Views.OpClaimHeaders.ActualTableName };
            this.CurSQLFactory.SelectCommand(ParametersGroup, Tables);

            if (this.TryConnection())
            {
                try
                {
                    ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                    if (ResultTable == null)
                    {
                        this.ErrMsg = "[ClaimManager.QueryClaimHeader] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                    }
                }
                catch (Exception ex)
                {
                    this.ErrMsg = ex.Message;
                }
            }


            return ResultTable;
        }

        protected virtual DataTable QueryClaimHeaderSP(DatabaseParameters Parameters)
        {
            DataTable ResultTable = null;

            this.CurSQLFactory.ExecuteStoredProcedure( this.DataStructrure.StoredProcedures.GetClaimHeaderByID.ActualTableName,Parameters);

            if (this.TryConnection())
            {
                try
                {
                    ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL);

                    if (ResultTable == null)
                    {
                        this.ErrMsg = "[ClaimManager.QueryClaimHeaderSP] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                    }
                }
                catch (Exception ex)
                {
                    this.ErrMsg = ex.Message;
                }
            }


            return ResultTable;
        }

        #endregion

        #region QueryClaimItems


        protected virtual DataTable QueryClaimItems(DatabaseParameters Parameters)
        {
            DataTable ResultTable = null;

            this.CurSQLFactory.SelectCommand(Parameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);

            if (this.TryConnection())
            {
                try
                {
                    // claim item muz always in order
                    ResultTable = this.CurDBEngine.SelectQuery(this.CurSQLFactory.SQL + " ORDER BY " + this.DataStructrure.Tables.ClaimDetail.Order.ActualFieldName);

                    if (ResultTable == null)
                    {
                        this.ErrMsg = "[ClaimManager.QueryClaimItems] : Failed at this.CurDBEngine.SelectQuery('" + this.CurSQLFactory.SQL + "') : " + this.CurDBEngine.ErrorMessage;
                    }
                }
                catch (Exception ex)
                {
                    this.ErrMsg = ex.Message;
                }
            }

            return ResultTable;
        }
        #endregion

        #region InsertClaimHeader
        protected virtual bool InsertClaimHeader(DatabaseParameters ValParameters)
        {
            bool smooth = true;

            if (this.TryConnection())
            {
                this.CurSQLFactory.InsertCommand(ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.ErrMsg = this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                smooth = false;
            }

            return smooth;
        }
        #endregion

        #region UpdateClaimHeader
        protected virtual bool UpdateClaimHeader(DatabaseParameters KeyParameters, DatabaseParameters ValParameters)
        {
            bool smooth = true;

            if (this.TryConnection())
            {
                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.ErrMsg = this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                smooth = false;
            }

            return smooth;
        }
        #endregion

        #region DeleteClaimHeader
        protected virtual bool DeleteClaimHeader(DatabaseParameters KeyParameters)
        {
            bool smooth = true;

            if (this.TryConnection())
            {
                this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructrure.Tables.ClaimHeader.ActualTableName);
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.ErrMsg = this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                smooth = false;
            }

            return smooth;
        }
        #endregion

        #region InsertClaimDetail
        protected virtual bool InsertClaimDetail(DatabaseParameters ValParameters)
        {
            bool smooth = true;

            if (this.TryConnection())
            {
                this.CurSQLFactory.DeleteCommand(ValParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.ErrMsg = this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                smooth = false;
            }

            return smooth;
        }
        #endregion

        #region UpdateClaimDetail
        protected virtual bool UpdateClaimDetail(DatabaseParameters KeyParameters, DatabaseParameters ValParameters)
        {
            bool smooth = true;

            if (this.TryConnection())
            {
                this.CurSQLFactory.UpdateCommand(KeyParameters, ValParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.ErrMsg = this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                smooth = false;
            }

            return smooth;
        }
        #endregion

        #region DeleteClaimDetail
        protected virtual bool DeleteClaimDetail(DatabaseParameters KeyParameters)
        {
            bool smooth = true;

            if (this.TryConnection())
            {
                this.CurSQLFactory.DeleteCommand(KeyParameters, this.DataStructrure.Tables.ClaimDetail.ActualTableName);
                smooth = this.CurDBEngine.ExecuteQuery(this.CurSQLFactory.SQL);
                if (!smooth)
                {
                    this.ErrMsg = this.CurDBEngine.ErrorMessage;
                }
            }
            else
            {
                smooth = false;
            }

            return smooth;
        }
        #endregion

        #endregion

        #region Clean Up
        protected new void Dispose()
        {
            this.CurrentLogManager.Dispose();
            this.CurrentLogManager = null;

            base.Dispose();
        }
        #endregion
    }

   
}
